Skip to main content

How to Read One Setting of a Docker Image with docker image inspect --format

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

docker image inspect prints everything Docker knows about an image as a long block of JSON. When you need one value, such as which processor the image was built for or what it runs on start, --format picks it out. This guide reads two settings of nginx:alpine, with real output from Docker 29.9.3.

Syntax​

Syntax
docker image inspect --format '{{.FIELD}}' IMAGE
PartWhat it means
'{{.FIELD}}'A Go template naming the field, such as {{.Architecture}} or {{.Config.Cmd}}. Field names are case-sensitive
IMAGEThe image's name and tag, or its ID

The reference describes the command as "Display detailed information on one or more images", and Docker's formatting guide: "Docker supports Go templates which you can use to manipulate the output format of certain commands and log drivers." The single quotes work in PowerShell too.

Prerequisites​

  • Docker: Docker Desktop on Mac or Windows, running.
  • An image, such as nginx:alpine, downloaded with docker pull nginx:alpine.

Step 1: Read the Architecture​

Terminal
docker image inspect --format '{{.Architecture}}' nginx:alpine
Output
arm64

docker image inspect --format with the .Architecture field for nginx in a terminal, printing arm64.

arm64: the copy Docker pulled was built for Apple silicon, the processor of the Mac this ran on. The same command printed arm64 in PowerShell 7.

Step 2: Read the Start Command​

Terminal
docker image inspect --format '{{.Config.Cmd}}' nginx:alpine
Output
[nginx -g daemon off;]

docker image inspect --format with the .Config.Cmd field for nginx in a terminal, printing the start command nginx -g daemon off;.

A dot reaches inside a section: .Config.Cmd is the Cmd field of the Config section, the command a container runs when it starts.

Common Mistakes​

MistakeWhat happensDo this instead
Writing the field in lowercasetemplate parsing error: template: :1:2: executing "" at <.architecture>: map has no entry for key "architecture"Match the JSON's capital letters: {{.Architecture}}
Expecting the full JSON with --formatOnly the field you name is printedLeave --format out to see every field, and their exact names

Troubleshooting​

SymptomLikely causeFix
map has no entry for keyThe field name is misspelled or in the wrong caseRun docker image inspect IMAGE without --format and copy the name from the JSON

FAQ​

How do I see which fields exist?​

Run docker image inspect nginx:alpine without --format: the JSON it prints has every field, with the names to use.

Does this work for containers too?​

Yes, docker container inspect --format takes the same kind of template for a container's settings: docker container inspect --format '{{.State.Status}}' web printed running.

Conclusion​

docker image inspect --format '{{.Architecture}}' nginx:alpine printed arm64, and {{.Config.Cmd}} printed the start command. Copy field names from the full JSON, capital letters included.

Additional Resources​