Docker Tutorial

Docker Installation

How to use Docker

Docker Instance

Docker Container Lifecycle Command

Docker Container Operation Command

Docker Container rootfs Command

Docker Mirror Repository Command

Docker Local Image Management Command

Docker info|version Command

Docker images command

The docker images command allows you to list and manage the Docker images on your local system. This tutorial will guide you through the basics of using the docker images command.

  1. Prerequisites:

    • Install Docker on your system
    • Have at least one image on your system. If you don't have any images, you can pull an example image using the following command:
    docker pull ubuntu:20.04
    

    This command will download the ubuntu:20.04 image from Docker Hub.

  2. List Docker images:

    To display a list of Docker images on your system, run:

    docker images
    

    This will display a table with the following columns:

    • REPOSITORY: The name of the image repository.
    • TAG: The image tag.
    • IMAGE ID: The unique identifier of the image.
    • CREATED: The time the image was created.
    • SIZE: The size of the image.
  3. Filter Docker images:

    You can use filters to narrow down the list of images being displayed. To do this, use the --filter or -f flag followed by the filter you want to apply.

    For example, to display only images from the "ubuntu" repository, use:

    docker images --filter 'reference=ubuntu:*'
    

    This command will list all images whose repository name starts with "ubuntu".

  4. Display images with a specific tag:

    To display only images with a specific tag, you can use the REPOSITORY:TAG format.

    For example, to display only images with the "20.04" tag, use:

    docker images ubuntu:20.04
    
  5. Format the output:

    By default, the docker images command displays images in a table format. If you want to change the output format, you can use the --format or -f flag followed by a Go template string.

    For example, to display images with a custom format, use:

    docker images --format '{{.Repository}}:{{.Tag}}\t{{.Size}}' 
    

    This command will display images with the repository name, tag, and size, separated by tabs.

  6. Display image digests:

    To display the image digests along with the other details, use the --digests or -D flag:

    docker images --digests
    

    This will add a DIGEST column to the table, which displays the image digests.

  7. Display all images:

    By default, the docker images command only displays the top-level images. To display all images, including intermediate images, use the -a or --all flag:

    docker images -a
    

In this tutorial, we covered the basics of using the docker images command to list and manage Docker images on your local system. By using filters, specific tags, custom output formatting, and additional options, you can tailor the output to your specific needs and gain valuable insights into your Docker images.

  1. How to Use Docker Images Command:

    • Description: The docker images command provides a list of Docker images on your local system.
    • Code Example:
      docker images
      
  2. Listing Docker Images with Images Command:

    • Description: Docker images lists all images on the local system, including their repository, tag, image ID, and creation date.
    • Code Example:
      docker images
      
  3. Docker Images Command Options:

    • Description: The docker images command supports various options for customizing the output, including formatting, filtering, and more.
    • Code Example:
      docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
      
  4. Filtering Docker Images Output:

    • Description: Filter images based on criteria such as repository, tag, or image ID to narrow down the output.
    • Code Example:
      docker images --filter "reference=myimage:*"
      
  5. Sorting Docker Images with Images Command:

    • Description: Sort images based on specific criteria, such as creation date or size, to organize the output.
    • Code Example:
      docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | sort -k3 -h
      
  6. Viewing Image Sizes with Docker Images:

    • Description: The docker images command displays the size of each image, helping you understand the storage impact of different images.
    • Code Example:
      docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
      
  7. Docker Images and Image IDs:

    • Description: Each image is identified by a unique image ID. Understanding image IDs is essential for various Docker operations.
    • Code Example:
      docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}"
      
  8. Inspecting Docker Images Details with Images Command:

    • Description: The docker images command provides a summary, but you can use docker inspect for more detailed information about a specific image.
    • Code Example:
      docker inspect <image_id>
      
  9. Removing Docker Images with Images Command:

    • Description: Use the docker rmi command to remove one or more images from the local system.
    • Code Example:
      docker rmi <image_id>
      
  10. Docker Images vs Docker ps:

    • Description: While docker images lists available images, docker ps shows running containers. They serve different purposes in managing Docker resources.
    • Code Example:
      docker ps