docker ps lists containers. By default it shows only the running ones.
Read the table
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f2b9c0d8e7a nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp webCONTAINER ID and NAMES both identify a container in other commands. COMMAND is what it runs, shortened to fit. STATUS shows how long it has been up. PORTS shows published and exposed ports; you may also see a second IPv6 entry such as [::]:8080->80/tcp.
Include stopped containers
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a8b7c6d5e4f alpine "false" 10 seconds ago Exited (1) 9 seconds ago jobThe number after Exited is the exit code. 0 normally means success and other values point to a problem. Use docker logs job to look for the reason. (The row for the running web container is left out here.)
Filter the list
$ docker ps -a --filter status=exited
$ docker ps --filter name=webThe name filter matches part of a name, so web also matches web2.
Only the IDs
-q prints just IDs, which is handy in scripts:
$ docker ps -aq --filter status=exited
9a8b7c6d5e4fYou can pass that to another command. This removes all stopped containers whose status is exited, so check the list first:
$ docker rm $(docker ps -aq --filter status=exited)If the list is empty, docker rm complains that it needs an argument.
Choose columns
--format takes a template:
$ docker ps --format "table {{.Names}}\t{{.Status}}"
NAMES STATUS
web Up 5 minutesOther useful options are --no-trunc to show full values, -l for the most recently created container, and -s for sizes. docker container ls is the same command under another name.
docker ps is not the Linux ps command. To see processes inside a container, use docker top web. The processes lab covers Linux ps.
Try it
Run docker run --name oops alpine false. Find it with docker ps -a, read its exit code, then remove it.
Check your understanding
docker ps
All 4 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.