Table of Contents
Seeing What Is Running
Before you can manage containers, you need to know which ones exist on your system and which ones are currently running. Docker provides a small set of commands to list containers in different states, and to adjust how much information you see.
Listing Running Containers
The main command to see running containers is:
docker ps
This shows only containers that are currently running. The output is a table with several columns. For example:
CONTAINER ID shows a short identifier you can use in other commands. IMAGE shows which image the container was created from. COMMAND shows the process that is running inside the container. CREATED shows how long ago the container was created. STATUS shows whether the container is running and for how long. PORTS shows which ports are exposed and mapped. NAMES is a human readable name Docker assigns, or the name you chose.
For most everyday tasks, you only need the container ID or the name. You can stop or remove a container using either one.
Important: docker ps lists only containers that are currently running. Stopped containers do not appear unless you explicitly ask for them.
Listing All Containers Including Stopped Ones
To see every container that exists on your system, including those that have exited, use:
docker ps -a
The -a flag stands for "all". This output looks similar to docker ps, but the STATUS column may show "Exited" with an exit code and timestamp. This helps you see containers that ran in the past, completed their work, and are no longer active.
A typical workflow is to check docker ps when you want to know what is currently running, and docker ps -a when you want to clean up old containers or inspect the result of previous runs.
Showing Only the Latest Container
Sometimes you just want to see the last container that was created, for example right after running a new container and wanting to recall its ID or name. You can use:
docker ps -l
This shows the most recently created container, whether it is running or exited. You can combine this with the "all" flag as needed, but usually -l alone is enough in this situation.
Limiting the Number of Containers Shown
If you have a long history of containers, the full docker ps -a output can become noisy. Use the -n option to show only a certain number of the most recently created containers:
docker ps -a -n 5
This shows only the 5 most recent containers. The number can be adjusted to suit your needs. Without -a, -n still only affects running containers, which is usually less useful.
Formatting and Filtering Output
As you work with Docker more often, you may want to tailor the output of docker ps so that it shows only the information you care about.
To filter containers, use the --filter option. For example, to list only running containers created from a specific image:
docker ps --filter "ancestor=nginx"
Or to list containers with a certain name pattern:
docker ps --filter "name=web"
Filters can also work with status, such as "running" or "exited". This is useful when you have many containers and want to focus on a specific subset.
To change the columns or format, use the --format option. A common pattern is to show only the container ID and names:
docker ps --format "{{.ID}} {{.Names}}"
You can combine filters and formatting together when you need a compact, customized list of containers.
Checking Container Status Quickly
In practice, you will often use docker ps repeatedly when working with containers. For example, after starting a container, you might run docker ps to confirm it is running. After stopping or removing a container, you might run docker ps or docker ps -a to verify that it is gone or has exited.
Over time you will develop your own habits, but these basic commands cover almost all container listing needs:
docker ps for running containers.
docker ps -a for all containers.
docker ps -l for the last created container.
docker ps -a -n N to see a recent subset.