19.2.6 Inspect CLI Command
A focused guide to Inspect CLI Command, connecting core concepts with practical Docker and container operations.
docker inspect returns detailed, structured metadata about Docker objects — containers, images, networks, volumes, and nodes. The output is a JSON array containing every piece of configuration and runtime state that Docker tracks for the specified object. It is the authoritative source for a container's complete configuration, network settings, volume mounts, environment variables, resource limits, and current state.
Basic Syntax
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
The object type is inferred from the ID or name provided. Multiple objects can be inspected in one call.
Inspecting a Container
docker inspect my-container
Output is a JSON array with one element (the container object). The object contains hundreds of fields organized into top-level sections.
Key sections in the output:
| Section | What it contains |
|---|---|
Id | Full 64-character container ID |
Created | Creation timestamp (ISO 8601) |
Path and Args | The command being executed |
State | Current state: running, exited, paused, etc. |
Image | The image ID the container was created from |
ResolvConfPath | Path to the container's resolv.conf |
Mounts | All volume and bind mount configurations |
Config | Container configuration: env, labels, cmd, entrypoint |
HostConfig | Runtime configuration: memory, cpu, restart policy, ports |
NetworkSettings | IP address, MAC address, port bindings, networks |
Extracting Specific Fields with --format
The --format flag uses Go templates to extract specific values without processing the full JSON output:
# Get the container's IP address
docker inspect --format '{{.NetworkSettings.IPAddress}}' my-container
# Get the current state
docker inspect --format '{{.State.Status}}' my-container
# Get the exit code
docker inspect --format '{{.State.ExitCode}}' my-container
# Get the image ID
docker inspect --format '{{.Image}}' my-container
# Get the restart count
docker inspect --format '{{.RestartCount}}' my-container
Inspecting Multiple Containers
docker inspect my-container postgres-container redis-container
The output is a JSON array with one element per container, in the order specified.
Inspecting Images
docker inspect works on image IDs and tags:
docker inspect nginx:latest
docker inspect a1b2c3d4e5f6
Image inspection returns configuration baked into the image: environment variables, exposed ports, volumes, entrypoint, labels, and the layer history.
Inspecting Networks
docker inspect bridge
docker inspect my-custom-network
Returns network driver, subnet, gateway, connected containers, and IPAM configuration.
Inspecting Volumes
docker inspect my-volume
Returns the volume driver, mount point on the host, labels, and options.
Common Inspection Queries
IP address
docker inspect --format '{{.NetworkSettings.IPAddress}}' my-container
For containers on non-default networks:
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-container
Environment variables
docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' my-container
Port mappings
docker inspect --format '{{.NetworkSettings.Ports}}' my-container
Or as a JSON string:
docker inspect --format '{{json .NetworkSettings.Ports}}' my-container
Volume mounts
docker inspect --format '{{json .Mounts}}' my-container
Memory limit
docker inspect --format '{{.HostConfig.Memory}}' my-container
A value of 0 means no limit is set.
Restart policy
docker inspect --format '{{.HostConfig.RestartPolicy.Name}}' my-container
Was the container killed by OOM?
docker inspect --format '{{.State.OOMKilled}}' my-container
Container start and finish times
docker inspect --format 'Started: {{.State.StartedAt}} Finished: {{.State.FinishedAt}}' my-container
Output Format Options
Raw JSON
The default output is a JSON array. Pipe it to jq for flexible querying:
docker inspect my-container | jq '.[0].State'
docker inspect my-container | jq '.[0].NetworkSettings.Networks'
docker inspect my-container | jq '.[0].Mounts[] | select(.Type == "volume")'
Go template with json function
docker inspect --format '{{json .Config}}' my-container
This outputs the Config section as a compact JSON object (one line), easier to parse in scripts than the full output.
Inspecting Stopped Containers
docker inspect works on containers in any state — running, stopped, paused, created, or dead:
docker inspect stopped-container
All configuration and final state information is available. The State.ExitCode and State.FinishedAt fields are populated once the container has exited.
Using docker inspect in Scripts
STATE=$(docker inspect --format '{{.State.Status}}' my-container 2>/dev/null)
if [ "$STATE" = "running" ]; then
echo "Container is running"
fi
IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' my-container)
curl http://$IP:8080/health