← All guides

Docker: List & Check Running Containers (docker ps, inspect)

Updated:
docker ps                        # running containers
docker ps -a                     # all containers, including stopped
docker ps -a -f status=exited    # only stopped containers
docker inspect -f '{{.State.Status}}' web   # status of one container

docker ps is the classic command; docker container ls is its newer, identical alias (docker container ls -a = docker ps -a). Everything below works with either form.

Cheat Sheet

Task Command
List running containers docker ps
List all containers (running + stopped) docker ps -a
List only stopped/exited containers docker ps -a -f status=exited
List containers created but never started docker ps -a -f status=created
List restarting (crash-looping) containers docker ps -f status=restarting
List unhealthy containers docker ps -f health=unhealthy
Show only container IDs docker ps -q / docker ps -aq
Show the last created container docker ps -l
Show disk size of each container docker ps -s
Don't truncate IDs and commands docker ps --no-trunc
Filter by name docker ps -f name=web
Filter by image docker ps -f ancestor=nginx
Filter by label docker ps -f label=env=prod
Containers of one Compose project docker compose ps
Live CPU and memory per container docker stats

Reading the Output

CONTAINER ID   IMAGE          COMMAND                  CREATED        STATUS                         PORTS                  NAMES
3f2a9c1e7b4d   nginx:1.27     "/docker-entrypoint.…"   2 days ago     Up 2 days (healthy)            0.0.0.0:80->80/tcp     web
9b81d2c4aa10   redis:7        "docker-entrypoint.s…"   2 days ago     Restarting (1) 8 seconds ago                          cache
c0ffee123456   myapp:latest   "node server.js"         5 hours ago    Exited (137) 3 hours ago                              worker

The STATUS column is the one that matters:

STATUS Meaning
Up 2 days Running
Up 2 days (healthy) / (unhealthy) Running, with the result of its HEALTHCHECK
Up 5 seconds (health: starting) Running, healthcheck not decided yet
Restarting (1) 8 seconds ago Crashing and restarted by the restart policy - see Docker container keeps restarting
Exited (0) Stopped cleanly
Exited (1) Stopped with an application error
Exited (137) Killed with SIGKILL - often the OOM killer or docker kill
Exited (143) Stopped with SIGTERM - a normal docker stop
Created Created but never started
Paused Frozen with docker pause

docker ps without -a hides everything that is not running - the most common reason people "lose" a container. Every status is explained in more detail in Docker container status.

Show Stopped Containers

docker ps -a -f status=exited                              # stopped
docker ps -a -f status=exited -f status=created            # stopped or never started
docker ps -a -f status=exited --format "{{.Names}}\t{{.Status}}"
docker ps -aq -f status=exited | wc -l                     # how many

Filters with the same key (status=exited, status=created) are combined with OR; filters with different keys (status, name) with AND.

Custom Output With --format

# Name, status and ports as a table
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

# Name, image and status, all containers
docker ps -a --format "{{.Names}}  {{.Image}}  {{.Status}}"

# JSON, one object per line (for jq)
docker ps -a --format '{{json .}}' | jq -r '.Names + " " + .State'

Available placeholders include .ID, .Image, .Command, .CreatedAt, .RunningFor, .Ports, .State, .Status, .Size, .Names, .Networks, .Labels and .Mounts.

Check if One Container Is Running

docker ps is meant for humans. In scripts, ask Docker for the state of a single container:

# running / exited / restarting / paused / created / dead
docker inspect -f '{{.State.Status}}' web

# true / false
docker inspect -f '{{.State.Running}}' web

# healthy / unhealthy / starting (only if the image defines a HEALTHCHECK)
docker inspect -f '{{.State.Health.Status}}' web

# Exit code of the last run, restart count, start time
docker inspect -f '{{.State.ExitCode}} {{.RestartCount}} {{.State.StartedAt}}' web

A check that exits non-zero when the container is down - usable in cron, CI or any monitoring tool:

#!/bin/sh
name="${1:?usage: $0 container}"
state=$(docker inspect -f '{{.State.Status}}' "$name" 2>/dev/null) || { echo "$name: not found"; exit 2; }
[ "$state" = "running" ] || { echo "$name: $state"; exit 1; }
health=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{end}}' "$name")
[ -z "$health" ] || [ "$health" = "healthy" ] || { echo "$name: $health"; exit 1; }
echo "$name: running${health:+ ($health)}"

Running Is Not the Same as Working

A container can be Up while the application inside is stuck, returns 500s or lost its database connection. Two ways to close that gap:

  • Define a HEALTHCHECK in the image or Compose file, so docker ps shows (unhealthy):

    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 30s
    
  • Check the service from outside - an HTTP or port check against the published port catches what an internal check cannot, such as a broken port mapping or firewall rule.

Docker Compose Containers

docker compose ps                     # services of the project in this directory
docker compose ps -a                  # including stopped
docker compose ps --status running
docker ps -f label=com.docker.compose.project=shop   # from anywhere on the host

Resource Usage and Logs

docker stats --no-stream                                              # one snapshot of all containers
docker stats --no-stream --format "{{.Name}}: {{.CPUPerc}} CPU, {{.MemUsage}}"
docker logs --tail 50 web                                             # last 50 lines
docker logs --since 10m web                                           # last 10 minutes
docker events --filter event=die --filter event=oom                   # live stream of crashes

docker events is handy while debugging: leave it running and every container that dies or is OOM-killed shows up immediately. For per-container CPU and memory trends, see monitor Docker container resource usage.

Get Alerted When a Container Stops

Listing containers tells you the state right now. To catch a container that stops, crash-loops or turns unhealthy while nobody is looking, run the check on a schedule and alert on its output. One command covers all three cases:

docker ps -a --format '{{.Names}} {{.Status}}' | grep -E 'Exited|Restarting|unhealthy'

Any output lists the containers that need attention; no output means everything is fine. If some containers are meant to stay stopped (one-off jobs, migrations), exclude them with grep -v.

In Zuzia, add this command as a scheduled task on the server and run it every few minutes. Zuzia keeps the output of every run with an AI summary, so you can see exactly when a container first went down. Add an HTTP or port check for the published service next to it - that one alerts you by email, Slack or SMS when the application stops answering, even if the container still shows Up.

FAQ

How do I list all Docker containers?

docker ps -a (or docker container ls -a) lists every container on the host, running or not.

How do I see only running containers?

docker ps with no flags shows only running containers. docker ps -q returns just their IDs.

How do I show stopped Docker containers?

docker ps -a -f status=exited. Add -q to get only their IDs, for example to pass them to docker rm.

What is the difference between docker ps and docker container ls?

None. docker container ls is the newer management-command name; docker ps remains as an alias with identical flags.

How do I check if a specific container is running?

docker inspect -f '{{.State.Running}}' <name> prints true or false. For a status word (running, exited, restarting) use {{.State.Status}}.

Why doesn't docker ps show my container?

It is not running. docker ps -a shows it, and docker logs <name> tells you why it exited.

What does Exited (137) mean?

The process was killed with SIGKILL - usually the kernel OOM killer when the container hit its memory limit, or a manual docker kill. Check docker inspect -f '{{.State.OOMKilled}}' <name>.

How do I see containers from Kubernetes pods?

On a Kubernetes node the runtime is usually containerd, not Docker. Use kubectl get pods from the cluster or crictl ps on the node - see monitoring Kubernetes pod status.

We use cookies to ensure the proper functioning of our website.