Docker: List Running and Stopped Containers

When you need to check which containers are running, see whether a container exited, or grab a container ID before another Docker command, the quickest tool is docker container ls. The older docker ps command works the same way.
This guide explains how to list Docker containers, show all containers including stopped ones, filter the output, and print only the fields you need.
Syntax
The docker container ls command uses this syntax:
docker container ls [OPTIONS]You can also use the older alias:
docker ps [OPTIONS]Docker also accepts docker container list and docker container ps. All four forms take the same options, and the examples in this guide use docker container ls.
List Running Docker Containers
To list the running containers, run the docker container ls command without any options:
docker container lsThe output will look something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e91d4f68fb49 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 5432/tcp pg
1403bbe0bb1f redis "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 6379/tcp cache
1e1eacc45cd6 nginx "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 80/tcp webEach line of the output includes the following columns:
Container ID- A unique alphanumeric string that identifies each container.Image- The Docker image that is used to create the container.Command- The command that is executed when starting the container.Created- The creation time of the container.Status- The status of the container.Ports- The container’s exposed ports and any published mappings between host and container ports.Names- The name of the container.
Docker lists the most recently created container first. If there are no running containers, only the header line is displayed. If you have not started any containers yet, see our guide to the docker run command .
List All Docker Containers
The -a, --all option tells docker container ls to print a list of all containers, including stopped ones:
docker container ls -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e91d4f68fb49 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 5432/tcp pg
50d08f6d0e96 hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago hello
1403bbe0bb1f redis "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 6379/tcp cache
1e1eacc45cd6 nginx "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 80/tcp webThe hello container printed its message and stopped. Its status is Exited (0), where 0 is the exit code of the main process in the container.
Use this form when docker container ls looks empty but you know containers were created earlier.
Show Full Output
By default, columns with a length exceeding a specified limit are truncated. Use the --no-trunc option to disable truncation:
docker container ls --no-truncWith --no-trunc, the CONTAINER ID column shows the full 64-character ID. The COMMAND column shows the complete command, such as /docker-entrypoint.sh nginx -g 'daemon off;' for the nginx container.
List Only Container IDs
To only display the containers’ IDs, pass the -q, --quiet option:
docker container ls -qe91d4f68fb49
1403bbe0bb1f
1e1eacc45cd6This is useful in scripts or when you want to pass container IDs to other Docker commands, for example when you remove Docker containers in bulk.
List Only Container Names
To print only container names, use the --format option:
docker container ls --format '{{.Names}}'pg
cache
webThis is a clean way to build shell loops or quick status checks without extra columns. You can also pass a name to docker exec to open a shell inside the container
.
Customize the Output Format
The --format option allows you to format the output using a Go template. For example, to print only the containers’ names and status, including the header, you would run:
docker container ls --format 'table {{.Names}}\t{{.Status}}'NAMES STATUS
pg Up 2 minutes
cache Up 8 minutes
web Up 12 minutesThis makes it easier to show only the fields you care about when checking container state.
The .Status field is written for people to read, so in scripts use .State instead. It prints a single word such as running or exited:
docker container ls -a --format 'table {{.Names}}\t{{.State}}\t{{.Status}}'NAMES STATE STATUS
pg running Up 2 minutes
hello exited Exited (0) 5 minutes ago
cache running Up 8 minutes
web running Up 12 minutesThe STATE column shows exited for the stopped hello container. The STATUS column adds the exit code and how long ago the container stopped.
Other placeholders you can use in the template include:
.ID- The container ID..Image- The image the container was created from..Command- The command that started the container..CreatedAt- The date and time the container was created..RunningFor- The time since the container was created, as shown in theCREATEDcolumn..Ports- The exposed and published ports..Size- The container disk size..Labels- All labels assigned to the container..Mounts- The volumes mounted in the container..Networks- The networks the container is attached to.
When you need machine-readable output for scripts, use json as the format:
docker container ls --format jsonEach container is printed as a JSON object on its own line, which works well with tools such as jq
.
Show Container Sizes
Use the -s, --size option to view the size of the containers:
docker container ls -sEach line will include a column named SIZE that shows the container size:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
e91d4f68fb49 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 5432/tcp pg 20.5kB (virtual 528MB)
1403bbe0bb1f redis "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 6379/tcp cache 4.1kB (virtual 176MB)
1e1eacc45cd6 nginx "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 80/tcp web 81.9kB (virtual 196MB)The writable size is shown first, followed by the virtual size of the image and container layers combined.
Show the Latest Containers
The -n, --last option tells the command to display the last n created containers, including all states. For example, to view the latest two created containers, you would run:
docker container ls -n 2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e91d4f68fb49 postgres "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 5432/tcp pg
50d08f6d0e96 hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago helloThe -n option counts every container, not only the running ones, so the stopped hello container is part of the result.
To list only the most recently created container, use -l, --latest, which is equivalent to -n 1:
docker container ls -lFilter Docker Containers
The --filter, -f option allows you to filter the output based on certain criteria.
For example, to view only the containers with status exited, you would run:
docker container ls -f "status=exited"CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
50d08f6d0e96 hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago helloYou do not need -a here; a status filter replaces the default view of running containers. The filter accepts created, restarting, running, removing, paused, exited, and dead.
You can also filter by container name:
docker container ls -f "name=web"The name filter matches part of a name, so the command above also lists a container named myapp-web-1. To match the exact name, wrap it in ^ and $:
docker container ls -f 'name=^web$'To show only running containers explicitly, use:
docker container ls -f "status=running"To list containers created from a specific image, use the ancestor filter:
docker container ls -f "ancestor=nginx"This matches containers whose image is nginx or an image built on top of it.
If you assign labels to your containers, you can filter on the label name or a specific key and value pair:
docker container ls -f "label=environment=production"For a list of all supported filters, check the Docker documentation .
List Containers in a Docker Compose Project
When your containers are managed by Docker Compose
, docker compose ps limits the list to a single project. Run the command from the directory that contains the Compose file, usually compose.yaml:
docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
myapp-cache-1 redis "docker-entrypoint.s…" cache About a minute ago Up About a minute 6379/tcp
myapp-web-1 nginx "/docker-entrypoint.…" web About a minute ago Up About a minute 0.0.0.0:8080->80/tcp, [::]:8080->80/tcpCompose names each container after the project, the service, and a replica number, so the web service in the myapp project runs as myapp-web-1. The project name defaults to the name of the directory that contains the Compose file.
Add the -a option to include stopped containers:
docker compose ps -aThe output includes only containers that belong to the Compose project, so it stays readable even when other containers run on the same host.
Quick Reference
For a printable quick reference, see the Docker cheatsheet .
| Task | Command |
|---|---|
| List running containers | docker container ls |
| List all containers | docker container ls -a |
| Show only container IDs | docker container ls -q |
| Show only container names | docker container ls --format '{{.Names}}' |
| Show full, non-truncated output | docker container ls --no-trunc |
| Show container sizes | docker container ls -s |
| Show latest container | docker container ls -l |
| Show last N containers | docker container ls -n 5 |
| Show only running containers | docker container ls -f "status=running" |
| Filter by status | docker container ls -f "status=exited" |
| Filter by exact name | docker container ls -f 'name=^web$' |
| Filter by image | docker container ls -f "ancestor=nginx" |
| List Compose project containers | docker compose ps |
| Custom output columns | docker container ls --format 'table {{.Names}}\t{{.Status}}' |
Troubleshooting
Cannot connect to the Docker daemon
The Docker daemon is not running. Start it with sudo systemctl start docker and run the command again.
permission denied while trying to connect to the docker API
Your user cannot access the Docker socket. Docker 28 and older print permission denied while trying to connect to the Docker daemon socket for the same problem. Run the command with sudo, or add your user to the docker group with sudo usermod -aG docker $USER and start a new shell session. The Docker installation guide
covers this step in detail. Membership in the docker group grants root-level privileges, so only add trusted users. If you need to run the daemon without root privileges, use Docker rootless mode
.
The output is empty even though containers were used before
Use docker container ls -a to include stopped containers, not only running ones.
FAQ
What is the difference between docker ps and docker container ls?
They are equivalent. docker ps is an alias, while docker container ls is the explicit management command.
Conclusion
To list Docker containers, use docker container ls or its alias docker ps. Add -a when you need stopped containers, and use --format or --filter when you want cleaner, task-specific output.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page