Skip to main content
Use 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:
Use the container ID or name from this output with 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:
Note: 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:
Useful flags:
  • -f or --follow: stream logs in real time (similar to tail -f).
  • --tail N: show only the last N lines.
Examples:
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

That’s the essential workflow for inspecting containers and viewing their logs.

Watch Video

Practice Lab