If you have lots of Docker Images on your host machine, then it might become difficult to keep track of all the images together. Moreover, many images even have the same name and only differ by tag names. In such cases, commands such as Docker image list might prove to be helpful. We can use the Docker images or Docker image list commands to list Docker images in our host machine.
Moreover, we can also use several filters that Docker allows us to use with the image list command to filter our results. We can list images all the unused images, filter images with tags, date of creation, and many more. In this article, we will learn how to list Docker images and learn to format and filter the results.
You can check our complete and free Docker tutorial. To install Docker, you can refer to the following guides.
Commands to list Docker Images
We can use two different commands to list all the Docker Images in our host machine. These are –
$ docker image ls

You can see that the output displays parameters such as repository and image name, tags, image ID, date of creation, and size of the image for all the images.
Another command to list Docker images is –
$ docker images

The output of both the commands is the same. The complete syntax of the Docker Image ls command is –
$ docker image ls [OPTIONS] [REPOSITORY[:TAG]]
Some important options that can be used along with the Docker Image ls command are –
Name | Shorthand | Description |
--all | -a | It is used to list all the images including intermediate images. |
--digests | Used to show the image digests as well. | |
--filter | -f | It is used to filter the output based on the conditions that we provide. |
--format | Used to pretty-print the list of images using a Go template. | |
--no-trunc | It is used to avoid truncating the output. | |
--quiet | -q | It is used to display only the image IDs. |
By default, both the commands does not list the unused and dangling images and the intermediate layers.
List Docker Images by Name and Tag
We can specify the [REPOSITORY[:TAG]] argument to list only those images that match with the argument.
Let’s list Docker Images that have a name called fedora.
$ docker images fedora

We can also list Docker Images by specifying both the name and tag.
$ docker images fedora:23

List Images Without Truncating
By default, when we use the Docker images command, it truncates the Image ID. To avoid doing so, we can use the –no-trunc option.
$ docker images --no-trunc

You can see that it has printed the complete Image ID without truncating it.
List Image Digests
Digests are content-addressable identifiers given to every Docker Image. We can use the –digests flag to print the digests of the image.
$ docker images --digests

Filter Image List Output
We can use the –filter option to filter the output according to our requirements. They are of the form of key-value pairs and we can also pass multiple filters together. The filters that are currently supported are –
- label (label=<key>=<value>, label=<key>)
- dangling (dangling=true/false)
- before (To filter images that were created before the given image, before=<image-ID>/<image@digest>/<image[:tag]>)
- since (To filter images that were created after the given image, after=<image-ID>/<image@digest>/<image[:tag]>)
- reference (Used to filter those images whose reference matches with the one specified)
Filter Untagged or Dangling Images
Untagged images are those images that are a leaf of the image tree. These are not intermediate layers. These images get automatically created when a new image build takes the repo:tag
away from the image ID and simply leaves it as <none>:<none>
.
$ docker images --filter "dangling=true"

Filter Images By Time
We can use the before filter to filter all images that were created before a particular image.
$ docker images --filter "before=ubuntu"

We can use the since filter to filter images that were created after a given image.
$ docker images --filter "since=ubuntu"

Filter Images by Reference
We can use the reference option to filter those images that matches with the specified pattern. For example, we can use the following command to all images starting with the letter f.
$ docker images --filter=reference='f*'

List All Docker Images
By default, Docker only lists those images that are not intermediate images. To avoid this, we can use the all option to list all the images.
$ docker images --all

List Only Image IDs
We can use the –quiet option to print only the Image IDs of all the images.
$ docker images --quiet

Format Image List Output
We can pretty-print the output with a Go template using the –format option. There are some placeholders that can be used with the format option.
Placeholder | Description |
---|---|
.Tag | Used to print the Image tag. |
.ID | It can be used to print the Image ID. |
.Repository | Used to print the repository name. |
.Digest | It can be used to print only the Image digest. |
.Size | To print the size of the image. |
.CreatedSince | Total time elapsed since the creation of the Image. |
.CreatedAt | Date of creation of Image. |
We can use the --format
option along with placeholders to either output the exact data declared by the template or, the column headers as well if we use the table
directive.
$ docker images --format "The ID of the image is {{.ID}} and repository name is {{.Repository}}"

$ docker images --format "table {{.Repository}}\t{{.ID}}\t{{.Size}}"

Final Thoughts!
In this article, we have discussed how to List Docker Images. We discussed two commands to do so along with several other options that they provide to filter and format the output. These includes options such as filter, format, quiet, all, etc.
We hope that you will now be able to understand the image list commands in detail. If you have any queries or suggestions, please mention them in the comment box and we will have our expert get back to you. Also, check out our complete Docker Tutorial for free.
Recommened Articles –
Happy Learning!
One comment