docker ps, docker inspect, and docker logs to get a quick overview, deep metadata, and runtime output from containers. This guide explains when to use each command, shows examples, and provides handy flags and tips.
Quick overview — docker ps
docker ps lists running containers and gives a short summary: container ID, image, command, age, status, ports, and name. It’s useful when you need to find a container ID or name quickly.
Example:
docker inspect and docker logs.
Container metadata — docker inspect
docker inspect <container> returns detailed JSON metadata for the specified container. This includes configuration, entrypoint, environment, mounts, state, and network settings.
Example:
docker inspect returns a JSON array even when inspecting a single container. To extract specific fields or produce human-readable output, either use Docker’s --format option or pipe the JSON to jq.
To extract a single field, use:
docker inspect --format '{{.State.Running}}' <container>- Or pipe the JSON to
jq:docker inspect <container> | jq '.[0].State'
Runtime output — docker logs
docker logs <container> shows what the container process writes to stdout and stderr. This is the first place to check when a containerized app is misbehaving or when verifying startup output. docker logs works best for containers started in detached mode (-d).
Example — run detached and view logs:
-for--follow: stream logs in real time (similar totail -f).--tail N: show only the last N lines.
Log availability depends on the container logging driver. Default drivers (like
json-file or journald) keep stdout/stderr accessible via docker logs. Some drivers (for example none or external drivers such as awslogs, syslog, or splunk) may not expose logs through docker logs.
Refer to the Docker logging drivers documentation: https://docs.docker.com/config/containers/logging/configure/Quick reference table
Links and references
- Docker: Inspect documentation — https://docs.docker.com/engine/reference/commandline/inspect/
- Docker: Logs documentation — https://docs.docker.com/engine/reference/commandline/logs/
- Docker: Configure logging drivers — https://docs.docker.com/config/containers/logging/configure/