Docker
Container Management
DevOps
Command Line
Software Development

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.

bash
docker ps

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.

bash
docker ps -a

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.

bash
docker ps -q

For all containers, combine the flags:

bash
docker ps -aq

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:

bash
docker ps --filter ancestor=nginx

Show only exited containers:

bash
docker ps -a --filter status=exited

Show only containers with a specific name fragment:

bash
docker ps -a --filter name=web

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.

bash
docker ps --format 'table {{.ID}}	{{.Names}}	{{.Status}}	{{.Image}}'

Or output only names:

bash
docker ps --format '{{.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 ps lists containers, which are runtime instances'
  • 'docker images lists 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:

bash
docker container ls
docker container ls -a

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:

  • 'Up means currently running'
  • 'Exited means the main process stopped'
  • 'Created means it was created but never started'
  • 'Restarting means 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.

bash
docker compose ps

This is often better than raw docker ps when the service names, networks, and project context matter.

Common Pitfalls

  • Using docker ps and forgetting it hides stopped containers by default.
  • Parsing the default table output in scripts instead of using --format or -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 ps to list running containers.
  • Use docker ps -a to include stopped containers.
  • Use -q for IDs and --format for script-friendly output.
  • Use filters to narrow the result set by image, name, or status.
  • If you work with Compose, docker compose ps can be the clearer operational view.

Course illustration
Course illustration

All Rights Reserved.