Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

List Running Containers

docker ps
docker container ls

Both commands are the same. Each line is one running container:

ColumnMeaning
CONTAINER IDShort ID
IMAGEImage it was started from
COMMANDMain process, shortened
CREATEDAge of the container
STATUSUp, Exited, Restarting
PORTSPublished and exposed ports
NAMESContainer name

Include Stopped Containers

CommandShows
docker ps -aAll containers
docker ps -lThe latest created
docker ps -n 3The last three created
docker ps -qIDs of running ones
docker ps -aqIDs of all

A stopped container keeps its files, settings, and logs until it is removed, which is why -a often shows more than you expect.

Filter the List

docker ps -a --filter "status=exited"
docker ps --filter "name=web"
docker ps -a --filter "ancestor=nginx:alpine"
docker ps --filter "health=unhealthy"
docker ps -a --filter "exited=137"
  • status: created, running, paused, restarting, removing, exited, or dead.
  • name: matches part of the name, so web also finds web-2.
  • ancestor: containers started from an image or one built on it.
  • health: starting, healthy, or unhealthy, for images with a health check.
  • exited: stopped containers with a given exit code; use it with -a.

Read the STATUS Column

  • Up 3 hours: running. A health check adds (healthy), (unhealthy), or (health: starting).
  • Exited (0) 5 minutes ago: the main process finished normally.
  • Exited (1): the application stopped with an error; read its output with docker logs.
  • Exited (137): the process was killed, often for memory; see exit code 137.
  • Restarting (1) 10 seconds ago: the container keeps failing and a restart policy keeps starting it; see Docker restart policy.
  • Created: the container exists but never started, often because a port was already taken.
  • Up 2 hours (Paused): its processes are frozen with docker pause.

Read the PORTS Column

An entry such as 0.0.0.0:8080->80/tcp means port 8080 on every IPv4 address of the host is forwarded to port 80 in the container. An IPv6 entry starting with [::] often appears beside it. 127.0.0.1:5432->5432/tcp is reachable only from the server itself. A bare 80/tcp is exposed by the image but not published. The details are in Docker port mapping.

Choose the Columns with --format

docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
docker ps -a --format "{{.Names}} {{.Status}}"

The table prefix keeps the header and aligns the columns. Without it, each container prints one line in the shape you give, which suits scripts. Other fields include {{.ID}}, {{.RunningFor}}, {{.Networks}}, and {{.Mounts}}.

Size and Full Output

docker ps -s
docker ps --no-trunc

-s adds a SIZE column: the data written in the container's own layer, and in parentheses the virtual size including the image. A large first number means the application writes inside the container instead of into a volume. --no-trunc prints full IDs and the whole command line.

Feed the List to Other Commands

docker stop $(docker ps -q)
docker rm $(docker ps -aq --filter "status=exited")

The first stops every running container; the second removes all stopped ones together with their writable layers. Check the list without -q before you run either. Safer variants are in how to stop all Docker containers.

Containers of a Compose Project

docker compose ps
docker compose ps -a

Run in the folder with the Compose file, this shows only that project's containers, with the service name. If docker ps answers with a permission error instead of a list, see cannot connect to the Docker daemon.

Was this answer helpful?
Loading...