A container stays on the host after its main process ends. docker ps shows the running ones. docker ps -a shows all of them.
text
docker run ... ─► running ──(process ends)──► exited ──(docker rm)──► gone
docker ps docker ps -aRunning containers
sh
docker pstext
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1dd94dc29ef nginx:1.27 "/docker-entrypoint.…" 6 seconds ago Up 6 seconds 80/tcp webAll containers
sh
docker ps -atext
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6df65503b990 alpine:3.20 "sh -c exit 1" 4 seconds ago Exited (1) 4 seconds ago festive_borg
99fddfcd7640 alpine:3.20 "echo hello" 6 seconds ago Exited (0) 6 seconds ago hello
e1dd94dc29ef nginx:1.27 "/docker-entrypoint.…" 8 seconds ago Up 8 seconds 80/tcp web| Column | Meaning |
|---|---|
CONTAINER ID | first 12 characters of the 64-character ID |
IMAGE | image the container was created from |
COMMAND | main process, truncated |
STATUS | Up <time>, Exited (<code>) <time> ago, Restarting, Created |
PORTS | ports the container listens on, and any published to the host |
NAMES | the name you gave with --name, or a generated one like festive_borg |
Exited (0) means the process finished successfully. Any other code is a failure worth reading the logs for.
Narrow the list
| Command | Output |
|---|---|
docker ps -q | IDs of running containers |
docker ps -aq | IDs of all containers |
docker ps -a --filter status=exited | stopped containers only |
docker ps -a --filter name=web | containers whose name contains web |
docker ps --filter status=running | same as docker ps |
-q output is meant for other commands, for example docker rm $(docker ps -aq --filter status=exited).
Choose the columns
--format takes a Go template with one placeholder per field:
sh
docker ps -a --format '{{.Names}} {{.Status}}'text
festive_borg Exited (1) 10 seconds ago
hello Exited (0) 12 seconds ago
web Up 14 secondsStart the template with table to keep aligned columns and a header:
sh
docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'text
NAMES IMAGE STATUS
festive_borg alpine:3.20 Exited (1) 12 seconds ago
hello alpine:3.20 Exited (0) 14 seconds ago
web nginx:1.27 Up 16 secondsUseful fields: {{.ID}}, {{.Names}}, {{.Image}}, {{.Command}}, {{.Status}}, {{.State}}, {{.Ports}}.