How to list images in Docker?

How to list images in Docker?
Techiio-author
Written by Nilima PaulFebruary 11, 2022
10 min read
Docker
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

We will know How to list images in Docker.

Introduction to Docker List Images

We need to utilize the 'docker picture list order to list Docker pictures that are locally accessible on the host on which we are running the order. 'ls' and 'pictures' are false names for this order which implies we can likewise run the order 'docker picture ls' or 'docker pictures' to list the Docker pictures. It has choices to control the result of the rundown of pictures according to our necessity. For instance, we can utilize the '- all' or '- a' to list all Docker pictures, including halfway pictures that are concealed as a matter of course.

Syntax

docker image list
docker image ls
docker images

Options:

-an or - all: It is utilized to show all pictures as halfway pictures are concealed naturally.

-digests: It is utilized to show the condensations of the picture.

-f or - channel: It is utilized to channel the pictures according to conditions determined

-design: This choice records the pictures prettier utilizing the Go layout

-no-trunc: If the result is getting shortening because of a little presentation, then, at that point, we can utilize this choice to not shorten the result.

–quiet: It is used to show only image Ids.

image list –help

How to list images in Docker?

It is extremely simple to list the Docker pictures; we just need to run any of the previously mentioned orders to list the Docker pictures; be that as it may, Docker CLI should be introduced on the host where we are running the order. It takes the order from the terminal and converts it to JSON arrangement, and settles on an API decision to the Docker daemon, and Docker daemon reacts with the rundown of the pictures accessible on the host.

Examples of Docker List Images

Let’s understand the command and its options using examples

Example #1

List images available on the host, excluding intermediate images.

We can use any of the below commands to list Docker images other than intermediate images:

docker image list
docker image ls
docker images

Example #2

List all images, including intermediate images.

  • Let’s build a Docker image using the below Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get install
nginx -y
cat Dockerfile
  • If we check the output carefully, we can see few images are used as highlighted in the below snapshot:
docker build -t custom-nginx:v1.

Explanation: – In the above preview, the primary featured numeric ID is the picture ID of the ubuntu, the second featured is the picture ID of the moderate picture, and the third one is the picture ID of the last picture. Middle of the road pictures don't have a store and tag, and when we list the pictures it shows <none> under the Repository and Tag section.

We can verify this by running the ‘docker image list –all’ command or using “-a” as below:

docker image list --all
docker image list -a

Example #3

Show the hash of Docker images.

  • We can use the ‘–digests’ command to output the digests of the images as below:
docker image list --digests

Explanation: In the above snapshot, we can see one more column added of DIGEST in the command’s output, and the recently created Docker image has no DIGEST as it is not signed.

We can even check the digest of any single Docker image as below:

docker image list ubuntu --digests

Example #4

Filter the Docker images.

We can use the “–filter” or “-f” option to filter out images based on the specified filter; for example, we can filter out the dangling image bypassing the ‘dangling=true’ condition as below:

docker image list --filter danling=true

Note – if the above command does not show any output, there is no dangling image. We can create a container and force remove the image that is used by the container and run the above command again to get the dangling image.

  • We can also use the ‘before’ or ‘since’ condition to list the images pulled before the specified image or after the specified image as below:
docker image ls
docker image ls --filter before=ubuntu
docker image ls --filter since=ubuntu

Example #5

Format the output of the ‘docker image list’ command.

  • We can use the ‘–format’ option to manipulate the output using the Go template; for example, if we only want to list the name of the repository with the tag, we can use the ‘–format’ option as below:
docker images --format “{{.Repository}}:{{.Tag}}”
  • We can see that the column heading is missing in the above snapshot; we can use the ‘table’ keyword in the Go template to show the column header as below:
docker images --format "table {{.ID}}\t{{.Repository}}:{{.Tag}}\t{{.Size}}"

Example #6

We want to show all output of the Docker images without truncating them. It can be done by using the “–no-trunc” option as shown below:

docker images --digests
docker images --digests –no-trunc

Explanation: – In the above snapshot, we can see that there is only one DIGEST shown if the ‘–no-trunc” is not used; however, when we use the “–no-trunc” option, we get one more digest that is truncated in the previous example.

Example #7

Just rundown the picture ID. It is conceivable in two ways, the first is by utilizing the '- peaceful' or the "- q" choice, and the subsequent one is by utilizing the "- design" choice by involving the Go layout as clarified before, nonetheless, the '- calm' choice is not difficult to utilize and quick.

docker images --quiet

Conclusion

The most brief and least demanding order to list the Docker pictures is the 'docker pictures. The parent order of this order is the 'docker picture'. We for the most part utilize the "- design' choice to robotize as it gives us yield how we want it.

Docker
Docker file
Containers
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance