Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Docker commands Guide – docker images with examples

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]]
Code language: CSS (css)

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
Code language: CSS (css)

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
Code language: CSS (css)

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
Code language: CSS (css)

Shows only the image with the tag 1.21 for nginx.


6. Filter Images by Dangling Status

docker images --filter "dangling=true"
Code language: JavaScript (javascript)

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"
Code language: JavaScript (javascript)

Lists images created before the nginx:latest image.

docker images --filter "since=python:3.9"
Code language: JavaScript (javascript)

Lists images created after the python:3.9 image.


8. Use Custom Formatting for Output

docker images --format "Repository: {{.Repository}}, Tag: {{.Tag}}, Size: {{.Size}}"
Code language: JavaScript (javascript)

Example Output:

Repository: nginx, Tag: latest, Size: 22.6MB
Repository: python, Tag: 3.9, Size: 885MB
Code language: CSS (css)

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
Code language: JavaScript (javascript)

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
Code language: JavaScript (javascript)

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 with docker 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

CommandDescription
docker imagesList all Docker images
docker images -aShow all images, including intermediate layers
docker images --digestsShow image digests
docker images nginxList 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 -qShow only image IDs
docker images --format "{{.Repository}}"Customize the output format

Best Practices for Using docker images:

  1. Regularly monitor and clean up images to save disk space.
  2. Use filters (--filter) to focus on specific images (dangling, older than a given image, etc.).
  3. Tag images properly for easy identification (e.g., my_app:dev, my_app:prod).
  4. Combine with docker rmi for automated cleanup scripts.
  5. Track image sizes and optimize Dockerfiles to reduce image bloat.

Common Errors and Solutions

  1. “No such image”
    โ†’ Ensure the image exists and is properly tagged. Use docker images to verify.
  2. “Image size too large”
    โ†’ Use multi-stage builds or switch to a smaller base image (alpine) to reduce size.
  3. “Dangling images taking too much space”
    โ†’ Use docker 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
Code language: JavaScript (javascript)

Check Disk Usage

docker system df

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Hereโ€™s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Hereโ€™s an in-depth, step-by-step tutorial and lab manual for Docker Networkingโ€”starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x