10 / 10

What is docker ps -a in Docker?

Difficulty: 4/10
container listing, status inspection, cleanup

docker ps -a (or docker ps --all) lists ALL containers on the system — both running and stopped. Without the -a flag, docker ps only shows currently running containers. It is one of the most frequently used Docker commands for inspecting container state, finding container IDs, and debugging.

Basic Usage
Understanding the Output
All Possible STATUS Values
  1. 1

    Up X hours/minutes — container is currently running

  2. 2

    Exited (0) — container stopped successfully (exit code 0 = success)

  3. 3

    Exited (1) — container stopped with error (non-zero = failure)

  4. 4

    Exited (137) — container was killed (SIGKILL — often OOM or docker kill)

  5. 5

    Created — container created but never started

  6. 6

    Paused — container is paused (docker pause was called)

  7. 7

    Restarting — container is in restart loop

  8. 8

    Removing — container is being removed

  9. 9

    Dead — container is in a broken state, needs force removal

Useful Flags with docker ps
Filtering with --filter (-f)
Custom Formatting with --format
Practical Combinations with docker ps -a
docker ps -a vs docker container ls -a
docker ps vs docker ps -a
  1. 1

    docker ps — shows ONLY running containers (STATUS: Up)

  2. 2

    docker ps -a — shows ALL containers regardless of state

  3. 3

    docker ps -q — shows only IDs of running containers

  4. 4

    docker ps -aq — shows only IDs of ALL containers

  5. 5

    docker ps -l — shows the most recently created container

  6. 6

    docker ps -n 5 — shows last 5 created containers

  7. 7

    docker ps -as — shows running containers with disk size info

Key Takeaways
  1. 1

    docker ps shows only running containers — always use -a to see everything

  2. 2

    The STATUS column is the most important — it tells you exactly why a container stopped

  3. 3

    Exit code 0 = clean stop, non-zero = error — use docker logs to investigate

  4. 4

    Use -q flag to get just IDs — essential for scripting bulk operations

  5. 5

    Use --filter to narrow down containers by status, name, image, or label

  6. 6

    Use --format for clean readable output or JSON for programmatic processing

  7. 7

    docker ps -aq is the foundation of most container cleanup scripts

Scenario Questions

0-2 years experience

  1. 1You need to verify whether a container that previously crashed is still present on the host. Which Docker command would you run, and what output would you look for?
  2. 2A teammate asks you to list all containers, including those that have stopped, so they can clean up old images. How would you do that?
  3. 3If you run `docker ps` and don't see a container you expect, what would you try next?

2-5 years experience

  1. 1During a CI pipeline, a test fails because a container that should be running is not listed by `docker ps`. How would you investigate using `docker ps -a` and what clues would you look for?
  2. 2You notice many exited containers accumulating on a host. Explain how you would use `docker ps -a` with filters to identify containers that exited more than 24 hours ago.
  3. 3A developer reports that `docker ps -a` shows a container with status 'Created' but it never started. What could cause this, and how would you debug it?

5-8 years experience

  1. 1Our monitoring system needs to periodically report the number of stopped containers across a fleet of hosts. Discuss the performance implications of using `docker ps -a` at scale and alternative approaches.
  2. 2Design a cleanup automation that safely removes exited containers without affecting running ones. How would you leverage `docker ps -a` output and what edge cases must you handle?
  3. 3Explain how you would integrate `docker ps -a` information into a centralized logging pipeline, considering high container churn and API rate limits.

8+ years experience

  1. 1We are moving from Docker CLI usage to a service‑oriented architecture with Kubernetes. How would you phase out reliance on `docker ps -a` in operational processes, and what replacement patterns would you propose?
  2. 2Across multiple teams, there is inconsistency in how container lifecycle is audited. Propose an organization‑wide policy that replaces ad‑hoc `docker ps -a` checks with a standardized observability solution.
  3. 3When designing a platform that supports both legacy Docker hosts and modern orchestrators, how do you ensure consistent visibility into container states without depending on `docker ps -a`?

Follow-up Questions

  • Which flag would you add to `docker ps` to see only running containers?
  • How can you pipe `docker ps -a` output to remove all exited containers in one command?
  • What does the STATUS column tell you about a container's lifecycle?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.