docker inspect prints everything Docker knows about a container as JSON: what it runs, how it is wired to the host, and what happened to it.
sh
docker inspect cachetext
[
{
"Id": "e1dd94dc29ef1a321f7709d199f32885061b9882187edc1bdae10321dd0fa25a",
"Created": "2026-10-11T20:49:08.100000000Z",
"Path": "docker-entrypoint.sh",
"Args": [
"redis-server"
],
"State": {
"Status": "running",
"Running": true,
...The four sections you need
| Key | Holds | Examples |
|---|---|---|
.State | What is happening now | Status, Running, ExitCode, StartedAt, FinishedAt |
.Config | What the container runs | Image, Cmd, Entrypoint, Env, Tty, OpenStdin |
.HostConfig | How Docker runs it on this host | RestartPolicy, PortBindings, Binds |
.NetworkSettings | Its network addresses | IPAddress, Ports |
Top-level keys include Name (with a leading /) and RestartCount.
Pull out one field: --format
--format (short -f) takes a Go template. A path of keys, each with a leading dot, selects a field:
sh
docker inspect --format '{{.State.Status}} {{.State.ExitCode}}' migratetext
exited 3sh
docker inspect --format '{{.HostConfig.RestartPolicy.Name}}' cachetext
alwayssh
docker inspect --format '{{.NetworkSettings.IPAddress}}' cache apitext
172.17.0.2
172.17.0.3Several containers in one command print one line each.
Lists and objects
Some fields are lists or objects. Three ways to print them:
| Template | Output |
|---|---|
{{json .Config.Env}} | The whole list as JSON on one line |
{{range .Config.Env}}{{println .}}{{end}} | One item per line |
{{index .Config.Env 2}} | Item 2 (counting from 0) |
sh
docker inspect --format '{{json .Config.Env}}' apitext
["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","PORT=8080","GREETING=Howdy","NAME=pier","LOG_LEVEL=debug"]sh
docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' apitext
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PORT=8080
GREETING=Howdy
NAME=pier
LOG_LEVEL=debugThe one-per-line form is exactly the --env-file format, so it can be saved and reused.
sh
docker inspect --format '{{json .HostConfig.RestartPolicy}}' apitext
{"Name":"on-failure","MaximumRetryCount":3}Common questions
| Question | Template |
|---|---|
| Is it running? | {{.State.Status}} |
| Why did it stop? | {{.State.ExitCode}}, then docker logs |
| What did it run? | {{json .Config.Entrypoint}} {{json .Config.Cmd}} |
| Which variables? | {{range .Config.Env}}{{println .}}{{end}} |
| Which ports? | {{json .HostConfig.PortBindings}} |
| Restarts on failure? | {{json .HostConfig.RestartPolicy}} |
| Its IP on the default bridge? | {{.NetworkSettings.IPAddress}} |