Docker command: images

In this blog post, we'll explore the docker images command and how it can help you in your containerization workflow. Learn how to list images used by containers and use filters to customize the output.

Docker command: images
Docker command: images

Docker Command: images

As a developer working with Docker, it's crucial to have a good understanding of the various Docker commands available to you. One such command is docker images. In this blog post, we'll explore the docker images command and how it can help you in your containerization workflow.

What is the Docker images Command?

The docker images command is used to list the images that have been downloaded and used by the created containers on your Docker host. It provides a convenient way to view the images that are available on your system and their corresponding details.

Listing Images Used by Containers

One of the key use cases for the docker images command is to list the images that are being used by the containers on your Docker host. This can be helpful when you want to get an overview of the images that are currently running or have recently been stopped.

To list the images used by the created containers, simply open your terminal and run the following command:

docker images

After running the command, you'll see a table that displays the list of images on your system, along with their image ID, repository, tag, and size. The output will look something like this:

REPOSITORY          TAG        IMAGE ID       CREATED           SIZE
nginx               latest     abcd1234       2 days ago        133MB
mysql               5.7        efgh5678       3 days ago        432MB

From the output, you can easily identify the images being used by the containers by checking the corresponding repository and tag columns. In the example above, the nginx and mysql images are being used by the containers.

Other Useful Options

The docker images command also provides some additional options that can be used to customize the output and filter the images based on specific criteria.

Displaying All Images

By default, the docker images command displays only the top-level images. To include all the images, including the intermediate layers, you can use the -a or --all option:

docker images -a

This will show all the images available on your system, including the intermediate layers used to create them.

Filtering Images by Repository or Tag

If you want to filter the images based on their repository or tag, you can use the -f or --filter option. For example, to display images with the repository name nginx, you can run:

docker images -f "repository=nginx"

This will only display the images with the repository name nginx.

Sorting Images by Column

If you want to sort the images based on a specific column, such as the size or the creation date, you can use the --format option along with the --sort option. For example, to sort the images based on the size in descending order, use the following command:

docker images --format "{{.ID}}\t{{.Size}}" --sort="-size"

This will display the images with their image ID and size, sorted in descending order based on the size.

Conclusion

The docker images command is a useful tool for listing the images that have been used by the created containers on your Docker host. By understanding how to use this command and its various options, you can easily view the images on your system, filter them based on specific criteria, and sort them based on different columns. This knowledge will help you effectively manage the images in your Docker environment and streamline your containerization workflow.

Now that you have a better understanding of the docker images command, give it a try on your own Docker host and explore the images available on your system.

Thank you for reading!