New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsDockerDocker
FreeSheet 02 of 11

Working with Images

A comprehensive developer cheatsheet covering Docker image management, featuring essential CLI commands and operational workflows for pulling, searching, inspecting, tagging, and removing Docker images.

Understanding Docker Images

What is a Docker Image?

A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software: code, runtime, system tools, libraries, and settings.

Image Naming Convention

text
[registry/][username/]image[:tag]
PartExamplePurpose
Registrydocker.ioRegistry hostname (default: Docker Hub)
UsernamenginxOwner of the image
ImagenginxImage name
Taglatest, 1.25, alpineVersion or variant

Examples:

  • nginx:latest — Official Nginx image, latest tag
  • nginx:1.25 — Nginx version 1.25
  • alpine:3.19 — Alpine Linux version 3.19
  • myuser/myapp:v1.0 — Custom image from myuser

docker pull — Download an Image

Downloads (pulls) an image from a registry.

Basic Usage

bash
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
9e1c7197b2c1: Pull complete
5b3bd6d9616b: Pull complete
Digest: sha256:abc123...
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

Common Flags

FlagPurpose
-a, --all-tagsDownload all tagged images
--platformSpecify platform (linux/amd64, linux/arm64)
-q, --quietSuppress verbose output

Examples

Pull specific version:

bash
$ docker pull nginx:1.25

Pull from a specific registry:

bash
$ docker pull myregistry.com/myapp:v1.0

Pull all tags:

bash
$ docker pull -a nginx

Pull for a specific platform:

bash
$ docker pull --platform linux/arm64 nginx

Pull with quiet output:

bash
$ docker pull -q nginx

docker images — List Local Images

Lists all locally stored Docker images.

Basic Usage

bash
$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED      SIZE
nginx         latest    abc123def456   2 days ago   187MB
alpine        3.19      456def789abc   5 days ago   7.05MB
ubuntu        22.04     789abc123def   2 weeks ago  77.8MB
myapp         v1.0      def456789abc   3 weeks ago  245MB

Common Flags

FlagPurpose
-a, --allShow all images (including intermediate)
-q, --quietShow only image IDs
--digestsShow digests
--filterFilter results (e.g., --filter "dangling=true")
--formatFormat output using Go template

Examples

Show only image IDs:

bash
$ docker images -q
abc123def456
456def789abc
789abc123def

Show with digests:

bash
$ docker images --digests
REPOSITORY    TAG       DIGEST                                 IMAGE ID       SIZE
nginx         latest    sha256:abc123...                       abc123def456   187MB

Filter dangling images:

bash
$ docker images --filter "dangling=true"

Filter by reference:

bash
$ docker images --filter "reference=nginx:*"

Format output as table:

bash
$ docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"

Format as JSON (using Go template):

bash
$ docker images --format '{{json .}}'

docker search — Search Docker Hub

Searches Docker Hub for images.

Basic Usage

bash
$ docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        18500     [OK]
nginx/nginx-ingress                NGINX Ingress Controller                        150
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGINX... 50
linuxserver/nginx                  Nginx is a web server...                        45

Common Flags

FlagPurpose
--limit NLimit number of results (max 100)
--filterFilter results (stars, is-official, is-automated)
--formatFormat output using Go template

Examples

Search with star filter:

bash
$ docker search nginx --filter stars=100

Search only official images:

bash
$ docker search nginx --filter is-official=true

Limit results:

bash
$ docker search nginx --limit 5

docker history — Show Image History

Shows the layer history of an image.

Basic Usage

bash
$ docker history nginx
IMAGE          CREATED       CREATED BY                                      SIZE
abc123def456   2 days ago    CMD ["nginx" "-g" "daemon off;"]               0B
def456789abc   2 days ago    STOPSIGNAL SIGQUIT                             0B
789abc123def   2 days ago    EXPOSE map[80/tcp:{}]                          0B
...

Common Flags

FlagPurpose
--no-truncDon't truncate output
-q, --quietShow only image IDs
--formatFormat output

Examples

Show full command (no truncation):

bash
$ docker history --no-trunc nginx

Show only image IDs:

bash
$ docker history -q nginx

docker inspect — Show Image Details

Shows detailed information about an image in JSON format.

Basic Usage

bash
$ docker inspect nginx
[
    {
        "Id": "sha256:abc123def456...",
        "RepoTags": [
            "nginx:latest"
        ],
        "RepoDigests": [
            "nginx@sha256:abc123..."
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2026-01-15T10:30:15.123456789Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.25.3"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
            ],
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            }
        },
        "DockerVersion": "20.10.23",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.25.3"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 187123456,
        "VirtualSize": 187123456
    }
]

Common Flags

FlagPurpose
-f, --formatFormat output using Go template

Examples

Get specific field (e.g., ExposedPorts):

bash
$ docker inspect nginx --format='{{.Config.ExposedPorts}}'
map[80/tcp:{}]

Get environment variables:

bash
$ docker inspect nginx --format='{{.Config.Env}}'
[PATH=/usr/local/sbin:... NGINX_VERSION=1.25.3]

Get image size:

bash
$ docker inspect nginx --format='{{.Size}}'
187123456

Get specific field with jq:

bash
$ docker inspect nginx | jq '.[0].Config.Cmd'

docker rmi — Remove an Image

Removes one or more images.

Basic Usage

bash
$ docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:abc123...
Deleted: sha256:abc123def456...
Deleted: sha256:def456789abc...

Common Flags

FlagPurpose
-f, --forceForce removal (even if running)
--no-pruneDon't delete untagged parents

Examples

Remove multiple images:

bash
$ docker rmi nginx alpine ubuntu

Remove by image ID:

bash
$ docker rmi abc123def456

Force remove:

bash
$ docker rmi -f nginx

Remove all unused images:

bash
$ docker rmi $(docker images -q)

Remove dangling images:

bash
$ docker rmi $(docker images --filter "dangling=true" -q)

docker tag — Tag an Image

Creates a new tag for an existing image.

Basic Usage

bash
$ docker tag nginx:latest myregistry.com/mynginx:v1.0

Syntax

bash
$ docker tag [SOURCE] [TARGET]

Examples

Tag for Docker Hub:

bash
$ docker tag nginx:latest myusername/nginx:latest

Tag for private registry:

bash
$ docker tag nginx:latest myregistry.com/myapp:1.0

Tag with multiple tags:

bash
$ docker tag nginx:latest myapp:latest
$ docker tag nginx:latest myapp:v1.0

Tag for versioning:

bash
$ docker tag myapp:latest myapp:1.0.0
$ docker tag myapp:latest myapp:1.0
$ docker tag myapp:latest myapp:1

Quick Reference — Most Used Commands

TaskCommand
Pull an imagedocker pull nginx
Pull specific versiondocker pull nginx:1.25
List imagesdocker images
List image IDs onlydocker images -q
Search Docker Hubdocker search nginx
Show image historydocker history nginx
Inspect imagedocker inspect nginx
Get specific fielddocker inspect nginx --format='{{.Size}}'
Remove an imagedocker rmi nginx
Remove all imagesdocker rmi $(docker images -q)
Tag an imagedocker tag nginx:latest myapp:v1.0

Pro Tips

  1. Always use specific tags — avoid :latest in production.

  2. Clean up unused images regularly:

    bash
    docker rmi $(docker images --filter "dangling=true" -q)
  3. Check image size before pulling:

    bash
    docker search nginx --limit 1
  4. Use --platform for multi-architecture builds.

  5. Inspect images to understand what's inside.

  6. Use docker images --digests to see image hashes.

  7. Tag before pushing to registry.

  8. Pull images with -q in CI/CD to reduce logs.


Next in DockerRunning Containers