
Docker containers are lightweight, standalone environments that contain everything needed to run an application—code, runtime, libraries, and dependencies. A common task in container management is to list the containers and check essential fields such as STATUS
, PORTS
, IMAGE
, and others.
This article shows how to list containers in Docker.
The Short Answer
The main command to list containers is docker container ls
. Here is a quick reference of the most commonly used commands to list containers in Docker.
# List running containers
$ docker container ls
# List all containers (including stopped)
$ docker container ls --all
# Show the most recently created container
$ docker container ls --latest
# Show only container IDs
$ docker container ls --quiet
# Show exited containers
$ docker container ls --filter "status=exited"
docker container ls
Command Syntax
Below is the command syntax to list containers in Docker.
docker container ls [OPTIONS]
- The
[OPTIONS]
are the optional flags that modify the command behavior.
Common Options
Option | Description |
---|---|
-a , --all |
Show all containers including the exited ones (default shows only running) |
-q , --quiet |
Show only container IDs |
-l , --latest |
Show most newly created container |
--filter , -f |
Filter output by condition (example status, name, image) |
--no-trunc |
Don't truncate output |
--size |
Show disk usage of the containers. |
These options can be combined or modified to tailor the output for your specific administrative tasks.
Command Usage
List all containers.
console$ docker container ls --all
This command lists all containers, including those not running, giving you a complete overview of container history.
View newly created containers.
console$ docker container ls --latest
This shows the latest created container. It can help debug or track the last step in a deployment pipeline.
Filter containers by name or status.
console$ docker container ls --filter "name=web" $ docker container ls --filter "status=exited"
List the containers in a custom output format.
console$ docker container ls --format "{{.ID}}: {{.Names}} ({{.Status}})"
This command shows the specified fields of the containers.
View the size of all the containers.
console$ docker container ls --all --size
This command helps you to diagnose disk space usage by containers.
Conclusion
In this article, you learned how to list containers using Docker CLI commands. You explored different command options to list all containers, filter by status or name, check container resource usage, and format output. These commands help to check container visibility and system health. For more information, visit the Docker container ls reference page.
No comments yet.