Home About Me

Docker Image Commands You’ll Use All the Time

When working with Docker, image-related commands are among the first things you need to know. That includes checking Docker itself, listing local images, searching for images, pulling them, and removing the ones you no longer need.

Basic help commands

Before managing images, it helps to know a few commands for checking your Docker environment and viewing available options.

docker version

Docker version screenshot

docker info

Docker info screenshot

docker --help

Docker help screenshot

  • docker version: shows Docker version information.
  • docker info: displays more detailed environment information.
  • docker --help: lists supported commands and usage.

Working with images

List images on the local host

docker images

Local Docker images

The main columns shown by this command are:

  • REPOSITORY: the image repository source
  • TAG: the image tag
  • IMAGE ID: the image ID
  • CREATED: when the image was created
  • SIZE: the image size

Common options:

  • -a: list all local images, including intermediate image layers
    docker images -a
  • -q: display only image IDs
    docker images -q
  • --digests: show image digest information
    docker images --digests
  • --no-trunc: show full image information
    docker images --no-trunc

A single repository can have multiple tags, and each tag usually represents a different version of that image. Docker identifies them with the format REPOSITORY:TAG.

If you do not specify a tag and use only something like ubuntu, Docker will use ubuntu:latest by default.

Search for an image

You can search directly from the command line, or browse images on the Docker Hub website:

https://hub.docker.com

Command format:

docker search [OPTIONS] 镜像名字

docker search example

Useful options:

  • --no-trunc: show the full image description
    docker search --no-trunc
  • -s: list only images whose star count is not lower than the specified value
    docker search -s
  • --automated: show only images built with automated builds
    docker search --automated

Pull an image

To download an image locally:

docker pull 镜像名字[:TAG]

docker pull syntax

For example:

docker pull tomcat

docker pull tomcat step 1

docker pull tomcat step 2

If no tag is specified, Docker will pull the latest version by default.

Remove images

To delete images, use docker rmi.

docker rmi 某个XXX镜像名字ID

Remove a single image

docker rmi -f 镜像ID

Remove one image

Remove multiple images

docker rmi -f 镜像名1:TAG 镜像名2:TAG

Example:

docker rmi -f hello-world nginx

Remove multiple images

Remove all images

docker rmi -f $(docker images -qa)

Remove all images