docker inspectShow the full configuration and state of Docker objects
docker inspect prints everything Docker knows about a container, image, network or volume as JSON: state and exit code, OOM kills, health checks, IP addresses, mounts, env vars, limits. With -f and a Go template you pull out exactly the field you need.
docker inspect [OPTIONS] NAME|ID [NAME|ID...]You want to see, once, everything Docker records about a running container.
docker inspectReturn the low-level JSON for one or more objects: containers, images, networks, volumes.
inspect calls the matching API endpoint, such as GET /containers/<id>/json, and prints the response. For containers dockerd merges the stored config (/var/lib/docker/containers/<id>/config.v2.json and hostconfig.json) with live state: PID, start and finish times, exit code, OOMKilled, health-check history and network settings. Config is what was asked for: image, Cmd, Env, labels. HostConfig is how it runs: ports, mounts, limits, restart policy, log driver. NetworkSettings and Mounts show the result. -f runs the JSON through Go's text/template, with helpers such as json, range, index, join, upper and println. Because Env and labels are stored in plain text, anyone allowed to talk to the docker socket can read every secret passed with -e.
-f, --format TEMPLATEPrint chosen fields with a Go template{{json .Field}}Print a nested object as JSON (pipe it into jq){{range .List}}...{{end}}Loop over a list or map, e.g. .Mounts or networks{{index .Map "key"}}Read a map key with special characters, like a label--type TYPEcontainer, image, network, volume, ... when a name is ambiguous-s, --sizeAdd SizeRw and SizeRootFs for containersdocker inspect api | grep IPAddressMatches several fields (and empty ones), and breaks when the container is on more than one network.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' apidocker inspect -f '{{.State.status}}' apiTemplate fields are case-sensitive and must match the JSON keys exactly; this fails with 'can't evaluate field status'.
docker inspect -f '{{.State.Status}}' apiPassing secrets with -e and assuming they're hiddenThey're stored in plain text in Config.Env, visible through inspect and on disk.
Use mounted secret files or a secrets manager read at startupTry these on a Linux machine of your own. Each task has a hint and a solution.
Print only the exit code and OOMKilled flag of the batch container, separated by a space. What killed it?
In the sandbox, practise the json + jq pattern: turn ~/data/servers.txt into JSON objects and print only the names of servers that are not running.
Write the command to print each mount of container db as 'source -> destination', one per line.
docker inspectShow the full configuration and state of Docker objects
docker inspect prints everything Docker knows about a container, image, network or volume as JSON: state and exit code, OOM kills, health checks, IP addresses, mounts, env vars, limits. With -f and a Go template you pull out exactly the field you need.
docker inspect [OPTIONS] NAME|ID [NAME|ID...]You want to see, once, everything Docker records about a running container.
docker inspectReturn the low-level JSON for one or more objects: containers, images, networks, volumes.
inspect calls the matching API endpoint, such as GET /containers/<id>/json, and prints the response. For containers dockerd merges the stored config (/var/lib/docker/containers/<id>/config.v2.json and hostconfig.json) with live state: PID, start and finish times, exit code, OOMKilled, health-check history and network settings. Config is what was asked for: image, Cmd, Env, labels. HostConfig is how it runs: ports, mounts, limits, restart policy, log driver. NetworkSettings and Mounts show the result. -f runs the JSON through Go's text/template, with helpers such as json, range, index, join, upper and println. Because Env and labels are stored in plain text, anyone allowed to talk to the docker socket can read every secret passed with -e.
-f, --format TEMPLATEPrint chosen fields with a Go template{{json .Field}}Print a nested object as JSON (pipe it into jq){{range .List}}...{{end}}Loop over a list or map, e.g. .Mounts or networks{{index .Map "key"}}Read a map key with special characters, like a label--type TYPEcontainer, image, network, volume, ... when a name is ambiguous-s, --sizeAdd SizeRw and SizeRootFs for containersdocker inspect api | grep IPAddressMatches several fields (and empty ones), and breaks when the container is on more than one network.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' apidocker inspect -f '{{.State.status}}' apiTemplate fields are case-sensitive and must match the JSON keys exactly; this fails with 'can't evaluate field status'.
docker inspect -f '{{.State.Status}}' apiPassing secrets with -e and assuming they're hiddenThey're stored in plain text in Config.Env, visible through inspect and on disk.
Use mounted secret files or a secrets manager read at startupTry these on a Linux machine of your own. Each task has a hint and a solution.
Print only the exit code and OOMKilled flag of the batch container, separated by a space. What killed it?
In the sandbox, practise the json + jq pattern: turn ~/data/servers.txt into JSON objects and print only the names of servers that are not running.
Write the command to print each mount of container db as 'source -> destination', one per line.