How to list Docker Images?

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.

  1. How to install Docker on Ubuntu/Linux?
  2. How to install Docker on Windows?

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
Docker Image List
Docker Image List

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
Docker Images
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 –

--all-aIt is used to list all the images including intermediate images.
--digestsUsed to show the image digests as well.
--filter-fIt is used to filter the output based on the conditions that we provide.
--formatUsed to pretty-print the list of images using a Go template.
--no-truncIt is used to avoid truncating the output.
--quiet -qIt is used to display only the image IDs.
Docker Image LS Options

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
List Docker Images by Name
List Docker Images by Name

We can also list Docker Images by specifying both the name and tag.

$ docker images fedora:23
List Docker Images by Name and Tag
List Docker Images by Name and Tag

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
List Images Without Truncating
List Images Without Truncating

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
Printing Image Digests
Printing Image 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 –

  1. label (label=<key>=<value>, label=<key>)
  2. dangling (dangling=true/false)
  3. before (To filter images that were created before the given image, before=<image-ID>/<image@digest>/<image[:tag]>)
  4. since (To filter images that were created after the given image, after=<image-ID>/<image@digest>/<image[:tag]>)
  5. 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"
Filtering Dangling Images
Filtering Dangling Images

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"
Filter Images Before a given Image
Filter Images Before a given Image

We can use the since filter to filter images that were created after a given image.

$ docker images --filter "since=ubuntu"
Filter Images since a given Image
Filter Images since a given Image

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*'
Filter Images by Reference
Filter Images by Reference

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
Listing all Docker Images
Listing all Docker Images

List Only Image IDs

We can use the –quiet option to print only the Image IDs of all the images.

$ docker images --quiet
Listing image IDs
Listing image IDs

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.

.TagUsed to print the Image tag.
.IDIt can be used to print the Image ID.
.RepositoryUsed to print the repository name.
.DigestIt can be used to print only the Image digest.
.SizeTo print the size of the image.
.CreatedSinceTotal time elapsed since the creation of the Image.
.CreatedAtDate of creation of Image.
Placeholder for Format Option

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}}"
Format Placeholder
Format Placeholder
$ docker images --format "table {{.Repository}}\t{{.ID}}\t{{.Size}}"
Printing Table Headers
Printing Table Headers

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 –

  1. What are Docker Images?
  2. What is Docker?
  3. How to Build Docker Images?

Happy Learning!

One comment

Leave a Reply