Skip to content
Latchkey

docker inspect Command Reference

Return low-level information on Docker objects as JSON.

docker inspect outputs the full JSON metadata for one or more containers, images, volumes, or networks. In CI it is used with --format to pull out a single field such as health status, exit code, or assigned IP for use in scripts.

Common flags

  • --format - Go template to extract a field, e.g. "{{.State.Health.Status}}"
  • --type - restrict object type, e.g. container or image
  • -s, --size - include container size (with --type container)

Example

shell
docker inspect --format '{{.State.Health.Status}}' app-db
docker inspect --format '{{.State.ExitCode}}' app-tests
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' app-web

In CI

Poll docker inspect --format {{.State.Health.Status}} until it reports healthy before running tests against a dependency. Read {{.State.ExitCode}} to fail a job on a non-zero container exit when the container itself does not propagate status.

Key takeaways

  • --format extracts a single field instead of the full JSON blob.
  • Health status and exit code are common fields to gate or fail CI steps.
  • inspect works across containers, images, volumes, and networks.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →