Contents
Docker ps Tutorial: List Containers with Filters and Custom Formatting
docker ps lists containers. For the complete container workflow, see Container lifecycle.
Syntax
docker ps [options]
docker ps and docker container ls are the same command.
Options
| Option | Description |
|---|---|
-a, --all | List all containers, including stopped ones (by default, only running containers are listed) |
-q, --quiet | Output container IDs only |
-f, --filter condition | Filter results; you can use this more than once |
--format template | Customize the output format: table, json, or a Go template |
-n, --last number | Show the n most recently created containers (in any state) |
-l, --latest | Show the most recently created container |
-s, --size | Show container sizes |
--no-trunc | Don't truncate output (show full IDs and commands) |
Common --filter conditions:
| Condition | Example |
|---|---|
status | status=running, status=exited, status=created |
name | name=web (partial match) |
label | label=team=backend |
ancestor | ancestor=nginx:1.30-alpine (created from a particular image) |
exited | exited=137 (filter by exit code) |
publish | publish=8080 (using a particular port) |
network / volume | network=appnet, volume=pgdata |
health | health=unhealthy |
Examples
The environment has three containers: the running web (nginx) and worker1 (with the team=backend label), and the stopped stopped1.
Running and all containers
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c260b28b0630 alpine:3.23 "sleep 600" 2 seconds ago Up 2 seconds worker1
1ec4fdc5c592 nginx:1.30-alpine "/docker-entrypoint.…" 8 seconds ago Up 2 seconds 80/tcp web
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c260b28b0630 alpine:3.23 "sleep 600" 2 seconds ago Up 2 seconds worker1
17b5b9a8c9ce alpine:3.23 "true" 3 seconds ago Exited (0) 2 seconds ago stopped1
1ec4fdc5c592 nginx:1.30-alpine "/docker-entrypoint.…" 8 seconds ago Up 2 seconds 80/tcp web
$ docker ps -q
c260b28b0630
1ec4fdc5c592
docker ps doesn't list stopped1; it appears only with docker ps -a, with the status Exited (0). -q outputs IDs only, making them easy to pass to other commands.
Filtering
$ docker ps -a --filter status=exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17b5b9a8c9ce alpine:3.23 "true" 3 seconds ago Exited (0) 2 seconds ago stopped1
$ docker ps --filter name=work
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c260b28b0630 alpine:3.23 "sleep 600" 2 seconds ago Up 2 seconds worker1
$ docker ps --filter label=team=backend
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c260b28b0630 alpine:3.23 "sleep 600" 2 seconds ago Up 2 seconds worker1
Customizing fields
$ docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES IMAGE STATUS
worker1 alpine:3.23 Up 2 seconds
web nginx:1.30-alpine Up 3 seconds
table adds a header row, and \t (Tab) separates the fields. Common fields include .ID, .Names, .Image, .Status, .Ports, .CreatedAt, .Labels, and .Size. Use --format json to output JSON.
Container sizes and the latest container
$ docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
c260b28b0630 alpine:3.23 "sleep 600" 3 seconds ago Up 2 seconds worker1 4.1kB (virtual 9.1MB)
1ec4fdc5c592 nginx:1.30-alpine "/docker-entrypoint.…" 9 seconds ago Up 3 seconds 80/tcp web 86kB (virtual 66.8MB)
$ docker ps -n 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c260b28b0630 alpine:3.23 "sleep 600" 3 seconds ago Up 2 seconds worker1
- The first number in
SIZEis the size of the container's writable layer;virtualincludes the image. The nginx container wrote some temporary files on startup, so its size is 86kB. -n 1shows only the most recently created container.
Batch processing: remove all stopped containers
$ docker rm $(docker ps -aq --filter status=exited)
17b5b9a8c9ce
$(...) runs the command inside first, then passes its result (the IDs of all stopped containers) as arguments to docker rm. You can get the same result with docker container prune (see Freeing disk space).
PowerShell also supports the
$(...)syntax; Windows CMD doesn't, so usedocker container pruneinstead.
Related chapters
- Container lifecycle
- docker inspect: View detailed information about a single container
- docker compose commands:
docker compose ps
Exercises
Exercise: List all containers created from nginx:1.30-alpine, including stopped ones, and show only their names and statuses.
Answer
docker ps -a --filter ancestor=nginx:1.30-alpine --format "table {{.Names}}\t{{.Status}}"
FAQ
Why can't I see the container I just ran with docker ps?
docker ps lists **running** containers only. If a container has exited (for example, a one-off command or a failed startup), use docker ps -a.
Are docker ps and docker container ls the same?
Yes. docker ps, docker container ls, docker container list, and docker container ps are all the same command.
What's the difference between Exited (0) and Exited (1) in STATUS?
The number in parentheses is the exit code. 0 means the program exited successfully; a nonzero value means an error, and 137 means it was forcibly terminated (for example, due to insufficient memory). Use docker logs to find out why.
Updated October 14, 2026