Here’s a complete tutorial on docker images
, covering what it does, examples, and use cases.
What is docker images
?
docker images
is a Docker command that lists all available images on the local machine. It provides details like the repository name, tag, image ID, size, and the creation date of each image.
Key Features:
- Lists all locally available Docker images.
- Supports filtering, sorting, and formatting output.
- Helps manage and inspect images for size, age, and tags.
Basic Syntax
docker images [OPTIONS] [REPOSITORY[:TAG]]
Common Options:
-a
,--all
: Show all images, including intermediate layers.--digests
: Show image digests (SHA256 hash of the image).--format
: Customize the output using Go templates (e.g.,{{.Repository}}
).--filter
,-f
: Filter images based on criteria like dangling, before, since, and label.--no-trunc
: Show full image IDs and digests without truncation.
Examples of docker images
1. List All Docker Images
docker images
Example Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e21c333399e4 1 day ago 22.6MB
python 3.9 5b6b7b8932de 2 days ago 885MB
2. Show All Images, Including Intermediate Layers
docker images -a
This lists all images, including intermediate layers used during image builds.
3. Show Image Digests
docker images --digests
Example Output:
REPOSITORY TAG DIGEST IMAGE ID SIZE
nginx latest sha256:c95f7e6fdf92bc932f3cfad7bb9275d53f3af7c7e69c2c27dc28b7e60a7c5b61 e21c333399e4 22.6MB
4. List Images for a Specific Repository
docker images nginx
This lists all available tags for the nginx
image.
5. List a Specific Image by Tag
docker images nginx:1.21
Shows only the image with the tag 1.21
for nginx
.
6. Filter Images by Dangling Status
docker images --filter "dangling=true"
This lists dangling images (untagged images that are no longer associated with a container).
7. Filter Images by Creation Date (before
and since
)
docker images --filter "before=nginx:latest"
Lists images created before the nginx:latest
image.
docker images --filter "since=python:3.9"
Lists images created after the python:3.9
image.
8. Use Custom Formatting for Output
docker images --format "Repository: {{.Repository}}, Tag: {{.Tag}}, Size: {{.Size}}"
Example Output:
Repository: nginx, Tag: latest, Size: 22.6MB
Repository: python, Tag: 3.9, Size: 885MB
9. List Only Image IDs
docker images -q
Example Output:
e21c333399e4
5b6b7b8932de
10. List Images and Remove Dangling Ones
docker images --filter "dangling=true" -q | xargs docker rmi
This removes all dangling images.
11. Use docker images
in a Shell Script
#!/bin/bash
for image in $(docker images -q); do
echo "Found image: $image"
done
Use Cases for docker images
1. Image Management and Maintenance
- List all images to monitor image size and manage disk space.
- Example: Identify large images and remove them if not needed.
2. Debugging and Troubleshooting
- Use
docker images
to verify image availability before running containers. - Example: Ensure the correct version of an image is available for a specific service.
3. Continuous Integration and Deployment (CI/CD)
- Integrate
docker images
in CI/CD pipelines to check for the latest images. - Example: Use it to determine if a new image needs to be built.
4. Security and Auditing
- List images and verify that they are up-to-date and secure.
- Example: Regularly check for old or vulnerable images.
5. Automated Image Cleanup
- Use
docker images
withdocker rmi
to automate image cleanup scripts.
6. Track Image Changes and Updates
- Monitor different image tags for a repository to track updates.
List of Common docker images
Commands
Command | Description |
---|---|
docker images | List all Docker images |
docker images -a | Show all images, including intermediate layers |
docker images --digests | Show image digests |
docker images nginx | List all images for the nginx repository |
docker images --filter "dangling=true" | List all dangling images |
docker images --filter "before=nginx:latest" | List images created before nginx:latest |
docker images -q | Show only image IDs |
docker images --format "{{.Repository}}" | Customize the output format |
Best Practices for Using docker images
:
- Regularly monitor and clean up images to save disk space.
- Use filters (
--filter
) to focus on specific images (dangling, older than a given image, etc.). - Tag images properly for easy identification (e.g.,
my_app:dev
,my_app:prod
). - Combine with
docker rmi
for automated cleanup scripts. - Track image sizes and optimize Dockerfiles to reduce image bloat.
Common Errors and Solutions
- “No such image”
→ Ensure the image exists and is properly tagged. Usedocker images
to verify. - “Image size too large”
→ Use multi-stage builds or switch to a smaller base image (alpine
) to reduce size. - “Dangling images taking too much space”
→ Usedocker images --filter "dangling=true"
to identify and remove them.
Combining docker images
with Other Commands
Remove Old Images
docker images --filter "before=my_app:1.0" -q | xargs docker rmi
Check Disk Usage
docker system df
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND