Skip to main content
Use 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:
Example: inspect a container named blissful_hopper
Sample (truncated) JSON output:

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:
In documentation or automation, wrap Go templates and examples in code formatting to avoid rendering issues, e.g. {{.State.Status}}.

Quick command reference

Logs: view container stdout/stderr

Docker captures a container’s stdout and stderr and exposes it via docker 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.
Basic usage:
Example of typical log output (application messages):
Tips for troubleshooting and analysis:
  • Use -f to stream logs in real time while debugging.
  • Combine --tail with -f to limit initial output for large logs.
  • Pipe logs to standard Unix tools: docker logs CONTAINER | grep ERROR, or to jq when logs are JSON: docker logs CONTAINER | jq '.'.
  • Inspect LogConfig in docker inspect to confirm where logs are being sent.

Examples: combine inspect + logs

  1. Confirm container status before viewing logs:
  1. Get container IP and then check application logs:
That’s all for this article.

Watch Video

Practice Lab