✦ For everyone, free.

Practical knowledge for real and everyday life

Home

19.1.2 Images CLI Command

A focused guide to Images CLI Command, connecting core concepts with practical Docker and container operations.

The images CLI command, docker images (or equivalently docker image ls), supports a considerably richer filter and formatting syntax than its basic, default invocation suggests, and fluency with these specific options turns it from a simple listing command into a precise, scriptable querying tool.

Filter syntax in depth

The --filter flag supports several distinct filter types, each narrowing the listed images by a different criterion:

docker images --filter "dangling=true"
docker images --filter "before=my-api:1.4.0"
docker images --filter "since=my-api:1.3.0"
docker images --filter "reference=my-api:1.4.*"
docker images --filter "label=team=payments"

before and since filter relative to another image's creation time rather than an absolute date, useful for finding everything built before or after a specific known reference point in a project's build history; reference supports glob-style wildcard matching against the image name and tag, useful for finding every version matching a specific naming pattern.

Combining multiple filters

Multiple --filter flags combine with AND logic, narrowing results to only images matching every specified condition simultaneously:

docker images --filter "label=team=payments" --filter "dangling=false"

This combination finds every tagged (non-dangling) image specifically labeled as belonging to the payments team, which is considerably more precise than either filter applied alone.

Format template fields

The --format flag's Go template syntax has access to several specific fields beyond what the default table display shows, useful for constructing exactly the output structure a script actually needs:

docker images --format "{{.Repository}}:{{.Tag}} {{.Size}} {{.CreatedSince}}"
docker images --format "{{json .}}"
my-api:1.4.2 145MB 2 days ago

Requesting JSON output specifically through {{json .}} provides every available field in a single, reliably structured object per image, which is considerably more robust for script parsing than constructing a custom template string and then needing to parse that string's specific, potentially fragile formatting.

Showing image digests directly

docker images --digests
REPOSITORY   TAG      DIGEST                                                                   IMAGE ID
my-api       1.4.2    sha256:3f29a8c1d8e2b4f6a9c7d5e8b1f3a6c9d2e5f8b1a4c7d0e3f6a9c2d5e8b1f4a7   8a1f3c9b2e7d

This flag adds the full content digest directly to the listing output, useful for quickly confirming exactly which content a given tag currently points to without needing a separate docker inspect invocation just to retrieve that digest value.

Listing intermediate and untagged layers with --all

docker images -a

By default, docker images shows only top-level, tagged images; adding -a reveals every intermediate layer image as well, which is rarely needed for ordinary usage but occasionally useful when investigating exactly how many distinct layers a particular build history has actually accumulated.

Quiet mode for scripting

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

The quiet flag outputs only image IDs, one per line, with no other formatting at all, which is specifically designed to be piped directly into another command, such as removing every currently dangling image in a single combined command.

Disabling truncation for full output

docker images --no-trunc

By default, image IDs and digests are truncated to a shorter, more readable length in the table display; --no-trunc shows the full, untruncated value, which is necessary when a script or a subsequent command genuinely needs the complete, exact value rather than the abbreviated form convenient for human reading.

Common mistakes

  • Not using --filter combinations to narrow results precisely, instead scrolling through and manually scanning a much larger, unfiltered list.
  • Constructing a custom --format template string for scripting purposes rather than requesting full JSON output through {{json .}} for more robust, reliable parsing.
  • Forgetting --digests exists, separately running docker inspect against each image individually just to retrieve its content digest.
  • Using the default, truncated output in a script that actually needs the complete, untruncated image ID or digest value.
  • Not using quiet mode (-q) when piping image IDs directly into another command like docker rmi, instead attempting to manually extract IDs from the default table output.

The images CLI command's filter and formatting options turn a basic listing command into a precise, scriptable querying tool, and fluency with filter types, JSON-formatted output, digest display, and quiet mode for piping is what distinguishes routine, manual usage from genuinely efficient, automatable image inventory management.

Content in this section