✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Inspect CLI Command

The Inspect CLI Command in Docker reveals detailed info on containers, images, and networks for analysis and troubleshooting

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:

SectionWhat it contains
IdFull 64-character container ID
CreatedCreation timestamp (ISO 8601)
Path and ArgsThe command being executed
StateCurrent state: running, exited, paused, etc.
ImageThe image ID the container was created from
ResolvConfPathPath to the container's resolv.conf
MountsAll volume and bind mount configurations
ConfigContainer configuration: env, labels, cmd, entrypoint
HostConfigRuntime configuration: memory, cpu, restart policy, ports
NetworkSettingsIP 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

Verify that the container was deleted due to lack of memory

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