This post will cover topic related to ‘Listing Docker Images’ with multiple docker command examples and different scenerios. So this will help you to understand the command docker and options available in it. Also this post will explain you how to use docker command.
The docker images
command is used to list all Docker images that are currently stored locally on your system. Docker images are snapshots or templates of Docker containers, containing everything needed to run a container based on the image.
Here are several examples demonstrating the usage of docker images
:
Example 1: List all Docker images on the system.
docker images
This command displays a table with information about each image, including the repository, tag, image ID, and size.
Example 2: List Docker images with detailed information (verbose output).
docker images -a
Adding the -a
flag shows all images, including intermediate images that are not tagged and are usually hidden.
Example 3: Filter Docker images by repository name.
docker images nginx
This command filters images whose repository name contains “nginx”. It lists all images with “nginx” in their repository name.
Example 4: Show only the numeric IDs of Docker images.
docker images -q
Using the -q
flag outputs only the image IDs, which can be useful for scripting or automation tasks.
Example 5: Display Docker images in a specific format (using Go template).
docker images --format "{{.Repository}}:{{.Tag}}"
This command customizes the output format to show only the repository name followed by the tag for each image.
Example 6: Sort Docker images by creation date.
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}\t{{.Size}}" | sort -k 3
Here, images are sorted based on their creation date, with the oldest images displayed first.
Example 7: Display total disk space used by Docker images.
docker images --format "{{.Size}}" | awk '{sum+=$1} END {print sum}'
This command calculates and prints the total size of all Docker images currently stored on the system.
Example 8: List Docker images by filtering dangling images.
docker images --filter "dangling=true"
Using the --filter
flag with "dangling=true"
filters images that have no associated containers and are not tagged.
Example 9: Display the image history for a specific Docker image.
docker history nginx:latest
This command shows the history of layers that make up the nginx:latest
image, detailing each layer’s creation and size.
Example 10: Show Docker images in a tree-like structure.
docker images --tree
This experimental command displays Docker images in a hierarchical tree format, showing their relationships and dependencies.
To verify whether the docker images
command executed successfully, check the terminal or command prompt output. If the command runs without errors and displays a list of Docker images along with their details, it indicates that the command executed as expected.
Also check similar articles.
Uploading Docker Images to a Registry
Downloading Docker Images from a Registry
Building Docker Images from a Dockerfile
Listing Docker Containers
Executing Commands Inside Docker Containers
Discussion about this post