LinuxCommandLibrary

docker-inspect

Display detailed information about Docker objects

TLDR

Display information about a container, image, or volume using a name or ID

$ docker inspect [container|image|ID]
copy

Display a container's IP address
$ docker inspect [[-f|--format]] '\{\{range.NetworkSettings.Networks\}\}\{\{.IPAddress\}\}\{\{end\}\}' [container]
copy

Display the path to the container's log file
$ docker inspect [[-f|--format]] '\{\{.LogPath\}\}' [container]
copy

Display the image name of the container
$ docker inspect [[-f|--format]] '\{\{.Config.Image\}\}' [container]
copy

Display the configuration information as JSON
$ docker inspect [[-f|--format]] '\{\{json .Config\}\}' [container]
copy

Display all port bindings
$ docker inspect [[-f|--format]] '\{\{range $p, $conf := .NetworkSettings.Ports\}\} \{\{$p\}\} -> \{\{(index $conf 0).HostPort\}\} \{\{end\}\}' [container]
copy

Display help
$ docker inspect
copy

SYNOPSIS

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

PARAMETERS

--format, -f string
    Format output using a custom Go template (e.g., '{{.Name}}')

--pretty
    Print value as pretty-printed JSON for readability

--type string
    Limit output to specific type (container, image, volume, network, node, plugin, secret, service, task)

-h, --help
    Display help for inspect

DESCRIPTION

docker inspect retrieves low-level details about Docker objects like containers, images, volumes, networks, services, nodes, plugins, secrets, and tasks. It outputs data in JSON format by default, perfect for scripting, debugging, and automation.

Specify one or more names or IDs as arguments. The command queries the Docker daemon for comprehensive metadata, including configuration, state, mounts, environment variables, labels, and runtime stats.

Key features include customizable output via Go templates with --format, pretty-printed JSON with --pretty, and type filtering with --type. This enables extracting specific fields, e.g., container IP or image size, without parsing full JSON.

Ideal for troubleshooting (e.g., checking why a container fails), CI/CD pipelines, and monitoring tools. Note it shows historical data for stopped objects.

CAVEATS

Requires running Docker daemon; verbose JSON output by default; -f is deprecated (use --format); does not modify objects.

COMMON EXAMPLES

docker inspect mycontainer # Full container JSON
docker inspect --format '{{.NetworkSettings.IPAddress}}' mycontainer # Container IP only
docker inspect --type image myimage --pretty # Pretty image details

TEMPLATE FUNCTIONS

Supports Go template funcs like json, printf, title, lower, split for advanced formatting.

HISTORY

Part of Docker CLI since initial 2013 release (v0.5+); evolved with Docker Engine, adding type filtering in v1.12+ and template enhancements.

SEE ALSO

Copied to clipboard