In this post, we will cover the topic ‘List Docker Images in Kubernetes’ with multiple docker command examples and different scenerios wherever it is applicable. So this will help to understand the options available in docker command and how to use those commands and its option.
The docker images
command in Kubernetes is used to list all Docker images that are currently stored on your local machine. Docker images are templates used to create Docker containers, which are lightweight and portable virtual environments.
Here are some examples of how to use docker images
command:
Example 1: List all Docker images on the local machine.
$ docker images
This command will display a list of all Docker images along with details such as the image ID, repository, tag, and size.
Example 2: Filter images by repository name (e.g., nginx).
$ docker images nginx
It will list Docker images that have the repository name matching ‘nginx’.
Example 3: Display image digests along with other details.
$ docker images --digests
This command will include image digests (a hash of the image content) in the output.
Example 4: Show only the latest created images.
$ docker images --latest
It will list only the latest created Docker images.
Example 5: Display the size of each image.
$ docker images --format "{{.Repository}}:{{.Tag}} - {{.Size}}"
This command formats the output to show repository name, tag, and size for each image.
Example 6: Sort images by size.
$ docker images --format "{{.Size}}" | sort -n
This command sorts Docker images by size in ascending order.
Example 7: List images with their creation date.
$ docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}\t{{.Size}}"
This formats the output as a table with columns for repository, tag, creation date, and size.
Example 8: Display images that match a specific filter.
$ docker images --filter "dangling=false"
It will show Docker images that are not dangling (i.e., not untagged and not referenced by any container).
Example 9: Display total file size of all images.
$ docker images --format "{{.Size}}" | paste -sd+ - | bc
This command calculates the total size of all Docker images.
Example 10: Show only the unique image IDs.
$ docker images --quiet
It will display only the image IDs, which are useful for scripting and automation tasks.
To verify if the command has executed successfully, simply look for the expected output in your terminal or command prompt window. Ensure that the output matches the description provided for each example command.
Also check similar articles.
Upload Docker Images to Kubernetes Registry
Download Docker Images for Kubernetes
Build Docker Images for Kubernetes
Execute Commands Inside Running Kubernetes Containers
How to Create and Run a New Container in Kubernetes?
Discussion about this post