Introduction
Proper Docker container management is one key aspect of a successful multi-container app deployment. Listing containers is a standard management operation that allows users to obtain important information about container health, status, and configuration parameters.
This guide shows you how to list Docker containers.
Prerequisites
- Command-line access.
- Administrative privileges on the system.
- Docker installed.
How to List Docker Containers
Listing containers available on the system provides a user with the following information about each container:
- Container ID. A unique alphanumeric string for each container, which helps identify and distinguish between the containers.
- Image. The template used for the creation of the container.
- Command. An instruction executed when Docker started the container.
- Age. The time passed since the container was created.
- Status. The information on whether the container is running, stopped, or in error.
- Ports. Any ports forwarded to the container for networking.
- Name. An identifying string created by the user (for example, with the docker run command) or randomly generated by Docker.
The following sections provide information about two commands, docker ps
and docker container ls
, that output a container list.
docker ps
The docker ps
command (short for docker process status) is the original Docker command for listing containers. Below is the command syntax:
docker ps [options]
When executed without any options, the command outputs a list of running containers:
docker ps
The table below lists the options that the command accepts as part of its syntax:
Option | Description |
---|---|
-a , --all | Show all running and stopped containers. |
-f , --filter [condition] | Filter output based on [condition]. |
--format [string] | Format output based on a template. Possible values of [string] are table, table [go-template], json, and [go-template]. |
-n , --last [number] | Show [number] newest containers (all states). |
-l , --latest | Show the newest container (all states). |
--no-trunc | Disable output truncation. |
-q , --quiet | Show container IDs only. |
-s , --size | Show total file sizes. |
--help | Show help. |
docker container ls
The docker container ls
is a newer command for container listing intended to replace docker ps
in the future and ensure consistency across Docker CLI.
However, as of the Docker version 25.05, docker container ls
and docker ps
exist side by side as aliases. The commands perform all the same functions, have the same options, and can be used interchangeably.
For example, below is the docker ps
command for printing a list of containers with truncation disabled:
docker ps --no-trunc
Another way to write this command is by using docker container ls
:
docker container ls --no-trunc
List Docker Containers: Examples
A Docker container list can be customized using various options and combinations of options. The examples below illustrate some of the more common usage scenarios.
List All Containers
To list all containers, both running and stopped, add option –a
:
docker ps –a
Refer to the STATUS
column to learn about the state of the container.
Add the -q
(quiet) option to show the list of container IDs only:
docker ps –aq
View File Sizes
The default container list view does not show how much storage each container takes up. To list the total file size of each container, use the option –s
(size):
docker ps –s
The SIZE
column appears in the output, showing the relevant information.
See Most Recently Created Container
When working with many containers, it may be challenging to find the newest ones just by looking at the list. To list the latest created container only, use the option –l
(latest):
docker ps –l
While -l
outputs only the newest container on the host, -n
prints any number of recent containers. For example, to see the last three containers, type the following:
docker ps -n 3
The list now shows three items.
Conclusion
After reading this tutorial, you should be able to list containers available on your system and customize the list view according to your needs. The article also provided examples of the most frequent list actions in Docker.
Find other container management commands and much more in our Docker Commands Cheat Sheet.