Skip to main content

How To List Docker Images (Practical Examples)

Explore various ways to list Docker images using Docker commands

Bibin Wilson

In this blog post, we’ll explore various ways to list Docker images using Docker commands. We’ll also look at advanced filtering options to help you fine-tune your image list.

If you’re a developer or a DevOps engineer who works with Docker, you’ll find the docker image list command indispensable for your daily tasks related to Docker.

Not only daily tasks but also for CI/CD configurations. One such example is listing docker images and removing unwanted images at the end of the image build pipeline.

In this guide, we’ve covered all the essential commands you’ll need to manage your Docker images effectively.

Toward the end, we have summarized all the docker image list commands in a table for your quick reference.

List Docker Images

The docker image list or its shorter form docker images command is used to list all the Docker images that are locally stored on your workstation or server.

Lists all available Docker images on your local system.

docker images

Lists all images, including intermediate images.

docker images -a

Shows only the image IDs.

Here is an example output

~ docker images -q

1809475dc712
91582cfffc2d
cc8dc3fa2380
6a47e077731f
6a0560a40914
15c9d636cadd
46c5e66a9efa

Shows the digests along with other details.

docker images --digests

Listing Only Docker Image IDs

Sometimes, you might want to list only the IDs of Docker images stored on your local system. This is useful for scripting or when you need to perform batch operations on multiple images.

Here’s how you can do it:

Basic Command to List Only Image IDs

docker images -q

Lists the IDs of dangling (unused) Docker images.

docker images -q --filter "dangling=true"

List IDs of Images with a Specific Name

docker images -q nginx

Filtering Docker Image List

Filtering is a powerful feature that allows you to narrow down your Docker image list based on specific criteria.

This is particularly useful when you have a large number of images and need to find specific ones.

Here are some commonly used commands for filtering your Docker image list:

Lists only the dangling (unused) images.

docker images --filter "dangling=true"

Lists images that match the specified image name.

docker images --filter "reference=nginx"

Lists images with a specific label key-value pair.

docker images --filter "label=com.example.version=1.0"

Lists images that match the specified image ID.

docker images --filter "id=abcd1234"

Lists images created before or after the specified image.

docker images --filter "before=nginx"
docker images --filter "since=node"

Listing and Formatting Docker Images Output

When you’re dealing with a large number of Docker images, the default output can be overwhelming. Docker provides options to format the output, making it easier to read or parse.

To list and format Docker images, you can use the “docker images” command with the “–format” option and a Go template. This allows you to customize the output to suit your needs.

Go templates are a way to define custom output formats using placeholders. Here are some commonly used placeholders for formatting Docker images:

  1. {{.Repository}}: The repository name of the image
  2. {{.Tag}}: The tag associated with the image
  3. {{.ID}}: The unique identifier for the image
  4. {{.CreatedAt}}: The creation date of the image
  5. {{.Size}}: The disk space consumed by the image
  6. {{.VirtualSize}}: The virtual size of the image
  7. {{.Labels}}: Custom metadata labels associated with the image

Let’s look at practical examples to list and format Docker images:

Format the output based on the template provided.

docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
`

List only the image IDs and repository names.

docker images --format "{{.ID}}: {{.Repository}}"

List the image IDs along with their creation time.

docker images --format "{{.ID}}: {{.CreatedAt}}"

List the image IDs along with their size.

docker images --format "{{.ID}}: {{.Size}}"

In the following output you can see image sizes shown in human readable format.

docker images --format "{{.ID}}: {{.Size}}"

1809475dc712: 1.1GB
91582cfffc2d: 192MB
cc8dc3fa2380: 146MB
6a47e077731f: 69.2MB
6a0560a40914: 599MB
15c9d636cadd: 65.7MB
46c5e66a9efa: 5.35MB

List the image IDs, repository names, and sizes.

docker images --format "{{.ID}}: {{.Repository}} ({{.Size}})"
💡
By using these formatting options, you can customize the output to show only the information you need. This is particularly useful for scripting or when you need to quickly scan through a large list of images.

Docker Images Location

As you know, docker images are stored in a specific location on the server.

Typically the Docker images get stored in the /var/lib/docker directory. It could differ based on the operating system.

💡
Note: When you build a docker image, the images, and respective layers are reused from this location.

Docker Image List Commands Summary

Task DescriptionDocker Command (Images)
List Docker Images
List all Docker imagesdocker images
List all images, including intermediate onesdocker images -a
Show only image IDsdocker images -q
Show digests along with other detailsdocker images --digests
Listing Only Docker Image IDs
List only image IDsdocker images -q
List IDs of dangling (unused) imagesdocker images -q --filter "dangling=true"
List IDs of images with a specific namedocker images -q nginx
Filtering Docker Image List
List dangling (unused) imagesdocker images --filter "dangling=true"
List images that match a specific namedocker images --filter "reference=nginx"
List images with a specific label key-value pairdocker images --filter "label=com.example.version=1.0"
List images that match a specific IDdocker images --filter "id=abcd1234"
List images created before or after a specific imagedocker images --filter "before=nginx" or docker images --filter "since=node"
Listing and Formatting Docker Image Output
Format output based on a templatedocker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
List only image IDs and repository namesdocker images --format "{{.ID}}: {{.Repository}}"
List image IDs along with their creation timedocker images --format "{{.ID}}: {{.CreatedAt}}"
List image IDs along with their sizedocker images --format "{{.ID}}: {{.Size}}"
List image IDs, repository names, and sizesdocker images --format "{{.ID}}: {{.Repository}} ({{.Size}})"

Conclusion

We’ve gone through a lot of ways to list Docker images. From simple lists to more detailed ones, we covered it all. These commands are really helpful for anyone who uses Docker regularly.

We learned how to see all images and find specific ones using custom filters. These tips can make your work easier and save you time.

So, go ahead and try these commands yourself. The more you use them, the easier your work with Docker will become.

Thanks for reading! If you have any more tips or questions, feel free to share them in the comments.

Bibin Wilson