How to List Docker 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]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
c8bded53da86 postgres "docker-entrypoint.s…" 2 hours ago Up 2 hours 5432/tcp pg
571c3a115fcf redis "docker-entrypoint.s…" 4 hours ago Up 4 hours 6379/tcp cache
05ef6d8680ba nginx "nginx -g 'daemon of…" 2 hours ago Up 2 hours 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 published ports.Names– The name of the container.
If there are no running containers, only the header line is displayed.
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
b28cbaa91f15 couchbase "/entrypoint.sh couc…" 5 hours ago Exited (0) 3 hours ago db
c8bded53da86 postgres "docker-entrypoint.s…" 2 hours ago Up 2 hours 5432/tcp pg
571c3a115fcf redis "docker-entrypoint.s…" 4 hours ago Up 4 hours 6379/tcp cache
05ef6d8680ba nginx "nginx -g 'daemon of…" 2 hours ago Up 2 hours 80/tcp webUse 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-truncList Only Container IDs
To only display the containers’ IDs, pass the -q, --quiet option:
docker container ls -qc8bded53da86
571c3a115fcf
05ef6d8680baThis is useful in scripts or when you want to pass container IDs to other Docker commands.
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.
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 hours
cache Up 4 hours
web Up 2 hoursThis makes it easier to show only the fields you care about when checking container state.
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
c8bded53da86 postgres "docker-entrypoint.s…" 2 hours ago Up 2 hours 5432/tcp pg 63B (virtual 394MB)
571c3a115fcf redis "docker-entrypoint.s…" 4 hours ago Up 4 hours 6379/tcp cache 0B (virtual 98.2MB)
05ef6d8680ba nginx "nginx -g 'daemon of…" 2 hours ago Up 2 hours 80/tcp web 2B (virtual 126MB)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
b28cbaa91f15 couchbase "/entrypoint.sh couc…" 5 hours ago Exited (0) 3 hours ago db
c8bded53da86 postgres "docker-entrypoint.s…" 2 hours ago Up 2 hours 5432/tcp pgTo 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
b28cbaa91f15 couchbase "/entrypoint.sh couc…" 5 hours ago Exited (0) 3 hours ago dbYou can also filter by container name:
docker container ls -f "name=web"To show only running containers explicitly, use:
docker container ls -f "status=running"For a list of all supported filters, check the Docker documentation .
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" |
| Custom output columns | docker container ls --format 'table {{.Names}}\t{{.Status}}' |
Troubleshooting
Cannot connect to the Docker daemon
The Docker daemon is not running or the current user cannot access it. Start Docker and verify your user has permission to use the Docker socket.
permission denied while trying to connect to the Docker daemon socket
Run the command with sudo or add your user to the docker group, then start a new shell session.
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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page