List Docker containers and filter the results
Find running or stopped containers, inspect useful status fields, and select a deliberate scope before bulk operations.
docker ps lists running containers on the selected Docker daemon. Use docker ps -a to include stopped and newly created containers. docker container ls is the equivalent grouped command.
docker ps
docker ps -a
docker ps -q
docker ps -s
docker ps -n 5
docker ps -l
-q prints IDs, -s adds size information, -n 5 shows the five most recently created containers, and -l shows the latest created container. The last two include containers outside the running set; neither means “most recently restarted.” Add --no-trunc when complete IDs or commands matter.
The default columns identify the container, image, command, creation time, status, exposed or published ports, and name. Size output describes writable-layer size and virtual size, not every related volume, log, or shared disk allocation.
Filter before inspecting
docker ps -a --filter status=exited
docker ps -a --filter name=web
docker ps -a --filter ancestor=nginx:stable
docker ps -a --filter label=env=prod
docker ps --filter health=unhealthy
Use -a explicitly when looking for stopped containers. The name filter can match part of a name; it is not an exact-name assertion. An ancestor filter can also match descendants of the specified image, and a mutable image tag may now identify a different image than it did when an older container was created.
Health filtering applies to configured health checks. An unconfigured check is not evidence that an application is healthy, and running only establishes the container process state.
Format a concise view
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
docker ps --format 'table {{.ID}}\t{{.Image}}\t{{.RunningFor}}'
On a host with watch installed, refresh a view with:
watch -n 2 'docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
This is a live snapshot, not retained monitoring history. For scripts, prefer explicit fields or structured inspection over splitting the human-readable table into columns.
Apply a reviewed selection
Stopping every running container or deleting every exited container affects the entire selected daemon. A narrower label helps separate disposable jobs from services. This POSIX-shell example first prints exited job IDs for review:
docker ps -aq --filter status=exited --filter label=cleanup=approved > candidates.txt
cat candidates.txt
After reviewing that file and preserving needed data, remove only those IDs:
while IFS= read -r id; do
[ -n "$id" ] || continue
docker rm "$id" || exit 1
done < candidates.txt
An empty selection does nothing. No force option is used: a container that has restarted should not be silently killed. To stop a reviewed list instead, use docker stop with those IDs. Avoid blindly substituting an unreviewed docker ps -q into a destructive command.
Missing or remote containers
If a newly launched container disappears from docker ps, check docker ps -a, its logs, and its inspected state. It may have completed normally, failed immediately, or been removed with --rm.
Check docker context show when the list seems unrelated to your machine. For a configured remote context, docker --context production ps queries that daemon. SSH-based or authenticated TLS contexts are preferable to exposing an unauthenticated daemon socket; -H tcp://...:2376 alone does not configure client certificates.
See Docker container listing and Docker contexts.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan