19.2.2.2 Ps All Containers
A focused guide to Ps All Containers, connecting core concepts with practical Docker and container operations.
The -a flag on docker ps extends the output to include all containers regardless of their current lifecycle state. Without this flag, only running containers are shown. With -a, the listing covers every container that exists in the Docker daemon's records — including stopped, exited, paused, created (but never started), and dead containers.
Basic Usage
docker ps -a
Example output on a busy development machine:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "/docker-entrypoint" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp web
b2c3d4e5f6a7 postgres:15 "docker-entrypoint…" 30 minutes ago Up 30 minutes 5432/tcp db
c3d4e5f6a7b8 myapp:1.0.0 "./run" 1 hour ago Exited (0) 55 minutes ago app-test
d4e5f6a7b8c9 ubuntu:22.04 "bash" 2 hours ago Exited (130) 2 hours ago dev-session
e5f6a7b8c9d0 myapp:0.9.0 "./run" 1 day ago Exited (1) 23 hours ago app-failed
f6a7b8c9d0e1 python:3.12 "python3" 3 days ago Created unused-env
Container States Visible with -a
| STATUS value | Meaning |
|---|---|
Up X seconds/minutes/hours | Container is currently running |
Exited (0) X ago | Exited successfully (exit code 0) |
Exited (1) X ago | Exited with error (non-zero exit code) |
Exited (130) X ago | Stopped by Ctrl+C / SIGINT |
Exited (137) X ago | Killed by SIGKILL (e.g., OOM killer or docker kill) |
Created | Created with docker create but never started |
Paused | Frozen with docker pause, still allocated |
Restarting (N) X ago | Restarting after a crash, restart policy active |
Dead | In an unrecoverable state, needs manual removal |
Removing | Being removed, in transition |
Why Exit Codes Matter
The exit code in the STATUS column reveals why a container stopped:
(0)— The process completed normally.(1)— The application exited with an error (application-level failure).(2)— Misuse of shell built-ins.(126)— Command found but not executable.(127)— Command not found.(130)— Process killed by SIGINT (Ctrl+C).(137)— Process killed by SIGKILL, often from the OOM killer.(143)— Process killed by SIGTERM (graceful stop, e.g.,docker stop).
Combining -a with log inspection reveals what a container did before it exited:
docker logs app-failed
Retrieving All Container IDs
docker ps -a -q
Returns only IDs, one per line — useful for scripting:
# Remove all stopped containers
docker rm $(docker ps -a -q -f "status=exited")
# Remove every container (running and stopped)
docker rm -f $(docker ps -a -q)
Filtering the All-Containers List
Filters can be combined with -a to narrow results:
Show only exited containers:
docker ps -a -f "status=exited"
Show containers that exited with a non-zero code (failures):
docker ps -a -f "status=exited" --format "{{.Names}}\t{{.Status}}"
Show the most recently created container regardless of state:
docker ps -a -l
Show the N most recently created containers:
docker ps -a -n 10
Cleaning Up with ps -a
A common maintenance pattern uses -a to find and remove stopped containers before reclaiming image disk space:
# See what stopped containers exist
docker ps -a -f "status=exited"
# Remove them all
docker container prune -f
Or equivalently:
docker rm $(docker ps -a -q -f "status=exited")
Removing stopped containers often unblocks image removal because docker rmi refuses to delete images that any container — even stopped ones — still references.
The Created State
A container in Created state was initialized with docker create but docker start was never called. These containers hold all their configuration but have never executed:
docker ps -a -f "status=created"
Created containers can be started at any time:
docker start unused-env
Or removed if no longer needed:
docker rm unused-env
Comparing ps vs ps -a
| Scenario | docker ps | docker ps -a |
|---|---|---|
| Currently running containers | Shows | Shows |
| Stopped containers from previous runs | Hidden | Shows |
| Containers created but never started | Hidden | Shows |
| Paused containers | Shows | Shows |
| Dead containers pending removal | Hidden | Shows |
docker ps is the operational view (what is alive right now). docker ps -a is the complete inventory (everything that has been created and not yet removed).