LinuxCommandLibrary

docker-image

Manage Docker images (build, tag, remove)

TLDR

List local Docker images

$ docker image ls
copy

Delete unused local Docker images
$ docker image prune
copy

Delete all unused images (not just those without a tag)
$ docker image prune [[-a|--all]]
copy

Show the history of a local Docker image
$ docker image history [image]
copy

View documentation for docker image rm
$ tldr docker rmi
copy

SYNOPSIS

docker image COMMAND [OPTIONS]
Examples:
docker image ls [OPTIONS]
docker image pull NAME[:TAG]
docker image rm IMAGE [IMAGE...]
docker image build [OPTIONS] PATH | URL

PARAMETERS

ls | images
    List all Docker images available locally, often showing repository, tag, image ID, creation time, and size.

pull NAME[:TAG]
    Download an image or a repository from a remote registry (e.g., Docker Hub) to your local system.

build [OPTIONS] PATH | URL
    Construct a new image from a Dockerfile and a specified build context (usually a directory containing the Dockerfile and source files).

rm | rmi IMAGE [IMAGE...]
    Remove one or more images by their ID or name. This command requires the image to not be in use by any running containers.

inspect IMAGE [IMAGE...]
    Display detailed low-level information about one or more images, including configuration, layers, and metadata, often in JSON format.

tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
    Create a new tag for an existing image. This allows referring to the same image with a different name or version.

push NAME[:TAG]
    Upload an image or a repository from your local system to a remote registry, making it available for others to pull.

prune
    Remove all dangling images (those that are not tagged and not referenced by any container) and optionally all unused images.

DESCRIPTION

The `docker image` command provides comprehensive functionality for managing Docker images on a system. Images are read-only templates used to create Docker containers. This command allows users to perform various operations such as listing all local images, pulling images from a registry like Docker Hub, building new images from a Dockerfile, tagging images with different names or versions, removing unwanted images to free up disk space, inspecting image details, and pushing images to a remote registry. It is an essential part of the Docker workflow, enabling the creation, distribution, and lifecycle management of containerized applications. Understanding and effectively utilizing `docker image` is fundamental for anyone working with Docker.

CAVEATS

The `docker image` command is a subcommand of `docker`; it must be invoked as `docker image` and not as a standalone executable. Image removal (`docker image rm`) can fail if there are active containers or other images dependent on the image. Building images (`docker image build`) requires a Dockerfile and a build context; large contexts or inefficient Dockerfiles can significantly impact build times and image sizes. Heavy image usage can consume substantial disk space, necessitating regular cleanup with `docker image prune`.

IMAGE LAYERS AND CACHING

Docker images are constructed from a series of read-only layers. Each instruction in a Dockerfile typically generates a new layer. This layered architecture enables efficient caching during image builds, as unchanged layers can be reused from previous builds, significantly speeding up development. It also optimizes storage, allowing multiple images to share common underlying layers, thus reducing overall disk space usage.

IMAGE MANIFESTS

Beyond just layers, a Docker image is described by an image manifest. This is a JSON document that specifies crucial details about the image, such as its architecture (e.g., `amd64`, `arm64`), operating system, and a list of its constituent layers. The manifest is vital for Docker to correctly pull and run images on different system architectures and for verifying the image's integrity and content.

HISTORY

Docker was initially released in March 2013. The `docker image` subcommand structure was introduced as part of Docker's continuous efforts to modularize and organize its command-line interface. Prior to this, image-related operations like `docker images`, `docker rmi`, `docker pull`, and `docker build` were top-level commands. This shift, along with the introduction of `docker container`, `docker network`, and `docker volume` subcommands, aimed to create a more intuitive and hierarchical CLI, improving discoverability and consistency for users managing various Docker components as the platform matured and its feature set expanded.

SEE ALSO

docker(1), docker-container(1), docker-build(1), docker-rmi(1), Dockerfile(5)

Copied to clipboard