docker inspect & Go Templates
Everything Is in inspect
Every fact about a container - IP, mounts, env, limits, health, exit code - lives in one JSON document:
$ docker inspect web # the whole JSON (hundreds of lines)
$ docker inspect -f '{{.State.Status}}' web
running
$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web
172.17.0.2
$ docker inspect -f '{{.HostConfig.Memory}}' web
268435456
The -f format strings are Go templates. The three patterns that cover 95% of use:
| Pattern | Use |
|---|---|
{{.Path.To.Field}} | one value |
{{range .Mounts}}{{.Destination}} {{end}} | iterate a list |
{{index .Config.Labels "my.label"}} | keys with dots/dashes |
Tip: When you don't know the path, dump the full JSON and search it (docker inspect web | grep -i memory). Then codify the path with-ffor scripts and checks.
Scenario: Audits, monitoring scripts, CI gates and every lab checker you've run in this track are built on inspect -f. It's the read API of Docker operations.