How to list containers in Docker
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Listing containers is one of the first Docker tasks people learn, but there are several useful variations depending on whether you want only running containers, all containers, formatted output, or filtered results. The core command is docker ps, but serious day-to-day use usually involves flags. This guide covers the common forms and explains what each one is really showing you.
Show Running Containers
The default command lists only currently running containers.
Typical columns include:
- container ID
- image
- command
- creation time
- status
- ports
- container names
This is the command you usually want when checking what is active right now.
Show All Containers
Stopped containers are excluded from plain docker ps. To include them, use -a or --all.
This is useful when a container exited immediately and you want to inspect its status, name, or ID before debugging logs.
Show Only Container IDs
If you are scripting and only need the IDs, use quiet mode.
For all containers, combine the flags:
This is common in scripts that stop, remove, or inspect matching containers.
Filter the List
Docker supports filters so you can narrow the result set without piping through several extra tools.
Show only containers from a given image:
Show only exited containers:
Show only containers with a specific name fragment:
Filters become much more useful than plain output once a host runs several services.
Format the Output for Readability
The default table is fine interactively, but custom formatting is better for automation and dashboards.
Or output only names:
This is cleaner than parsing the default table with brittle text tools.
Understand the Difference Between Containers and Images
A common beginner mistake is confusing docker ps with docker images.
- '
docker pslists containers, which are runtime instances' - '
docker imageslists stored images, which are templates'
You can have many containers from one image, and you can have images with no running containers at all.
Use docker container ls If You Prefer Explicit Commands
Docker also supports the more explicit command form:
This is equivalent to docker ps and docker ps -a. Some teams prefer it because it reads more clearly alongside docker image ls and docker volume ls.
Container State Matters
When a container appears in docker ps -a, its status column tells you a lot about what happened:
- '
Upmeans currently running' - '
Exitedmeans the main process stopped' - '
Createdmeans it was created but never started' - '
Restartingmeans Docker is trying to restart it'
That status is often the fastest clue during debugging.
Compose Users Should Also Know docker compose ps
If the containers are managed by Docker Compose, the Compose view can be more meaningful because it groups services by project.
This is often better than raw docker ps when the service names, networks, and project context matter.
Common Pitfalls
- Using
docker psand forgetting it hides stopped containers by default. - Parsing the default table output in scripts instead of using
--formator-q. - Confusing images with containers.
- Looking only at running containers when the real problem is an exited container.
- Ignoring Compose-specific views when the stack is actually managed through
docker compose.
Summary
- Use
docker psto list running containers. - Use
docker ps -ato include stopped containers. - Use
-qfor IDs and--formatfor script-friendly output. - Use filters to narrow the result set by image, name, or status.
- If you work with Compose,
docker compose pscan be the clearer operational view.

