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.
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.
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:
{{.Repository}}: The repository name of the image
{{.Tag}}: The tag associated with the image
{{.ID}}: The unique identifier for the image
{{.CreatedAt}}: The creation date of the image
{{.Size}}: The disk space consumed by the image
{{.VirtualSize}}: The virtual size of the image
{{.Labels}}: Custom metadata labels associated with the image
Let’s look at practical examples to list and format Docker images:
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.
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 (authored over 300 tech tutorials) is a cloud and DevOps consultant with over 12+ years of IT experience. He has extensive hands-on experience with public cloud platforms and Kubernetes.
How To List Docker Images (Practical Examples)
Explore various ways to list Docker images using Docker commands
— Bibin Wilson
How To List Docker Images (Practical Examples)
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 formdocker 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.
Lists all images, including intermediate images.
Shows only the image IDs.
Here is an example output
Shows the digests along with other details.
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
Lists the IDs of dangling (unused) Docker images.
List IDs of Images with a Specific Name
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.
Lists images that match the specified image name.
Lists images with a specific label key-value pair.
Lists images that match the specified image ID.
Lists images created before or after the specified image.
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:
{{.Repository}}
: The repository name of the image{{.Tag}}
: The tag associated with the image{{.ID}}
: The unique identifier for the image{{.CreatedAt}}
: The creation date of the image{{.Size}}
: The disk space consumed by the image{{.VirtualSize}}
: The virtual size of the image{{.Labels}}
: Custom metadata labels associated with the imageLet’s look at practical examples to list and format Docker images:
Format the output based on the template provided.
List only the image IDs and repository names.
List the image IDs along with their creation time.
List the image IDs along with their size.
In the following output you can see image sizes shown in human readable format.
List the image IDs, repository names, and sizes.
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.Docker Image List Commands Summary
docker images
docker images -a
docker images -q
docker images --digests
docker images -q
docker images -q --filter "dangling=true"
docker images -q nginx
docker images --filter "dangling=true"
docker images --filter "reference=nginx"
docker images --filter "label=com.example.version=1.0"
docker images --filter "id=abcd1234"
docker images --filter "before=nginx"
ordocker images --filter "since=node"
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
docker images --format "{{.ID}}: {{.Repository}}"
docker images --format "{{.ID}}: {{.CreatedAt}}"
docker images --format "{{.ID}}: {{.Size}}"
docker 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 (authored over 300 tech tutorials) is a cloud and DevOps consultant with over 12+ years of IT experience. He has extensive hands-on experience with public cloud platforms and Kubernetes.