docker ps to list running containers (names and IDs). When you need deeper information about a container’s state, mounts, configuration, or networking, use docker inspect with the container name or ID. docker inspect returns detailed metadata in JSON format.
docker inspect always returns a JSON array (even for a single container). To extract specific fields or to pretty-print the output, use tools like jq or Docker’s --format option with Go templates.Inspect: get container metadata
Basic inspect command:blissful_hopper
Extract specific fields with --format
If you need a single field (for example the container status or IP), use --format with Go templates to avoid parsing the full JSON:
{{.State.Status}}.
Quick command reference
Logs: view container stdout/stderr
Docker captures a container’s stdout and stderr and exposes it viadocker logs (works for running and exited containers). Note that logs are available only through the configured logging driver — some drivers may forward logs to external systems and not keep them locally.
Some logging drivers (or custom logging configurations) send logs to external services and may not make them available via
docker logs. Verify the container’s LogConfig (via docker inspect) if you can’t retrieve logs with docker logs.- Use
-fto stream logs in real time while debugging. - Combine
--tailwith-fto limit initial output for large logs. - Pipe logs to standard Unix tools:
docker logs CONTAINER | grep ERROR, or tojqwhen logs are JSON:docker logs CONTAINER | jq '.'. - Inspect
LogConfigindocker inspectto confirm where logs are being sent.
Examples: combine inspect + logs
- Confirm container status before viewing logs:
- Get container IP and then check application logs:
Links and references
- Docker CLI: ps
- Docker CLI: inspect
- Docker CLI: logs
- jq — lightweight and flexible command-line JSON processor
- Go templates in Docker
--format(seedocker inspect --help)