726 words
4 min read

Essential Commands for Listing Docker Containers

By Docker Captain · CNCF Ambassador · IBM Champion
Cover image for the post 'Essential Commands for Listing Docker Containers'

If you don’t know what’s running in your Docker environment, you’re not running it. It’s running you.

Whether you’re babysitting a dev laptop with three containers or wrangling a prod swarm that never sleeps, listing containers is the first move in any troubleshooting dance. And yet, too many engineers treat docker ps like some dusty man page trick instead of what it is: a daily-use diagnostic scalpel.

Let’s fix that.

Why Listing Containers Actually Matters#

Here’s the deal: containers are cheap, disposable, and everywhere. That’s the whole point. But when you’ve got 47 of them doing who-knows-what at 3AM during an incident, you better be able to see exactly what’s up, fast.

Here’s what container listings tell you (if you know how to read them):

  • What’s running: or more importantly, what’s not
  • Which ports are exposed (and why Jenkins is talking to the wrong service)
  • Which ones just crashed five times in a row
  • Who deployed that random PostgreSQL container last week
  • How much disk space your zombie containers are chewing up

You want operational clarity? It starts with docker ps.

Core Commands: No Fluff, Just Output#

Let’s walk through the container listing commands that matter: the ones I actually use when things break.

List Running Containers#

Terminal window
docker ps

This is the default. It shows only running containers, none of your sad, exited ghosts.

Fields you’ll see:

  • CONTAINER ID
  • IMAGE
  • COMMAND
  • CREATED
  • STATUS
  • PORTS
  • NAMES

If all you need is to check what’s up and listening on port 8080, this is your guy.

See All Containers (Even the Dead Ones)#

Terminal window
docker ps -a

Want to know why that database backup failed overnight? This is where your exited containers live.

Useful for:

  • Postmortems
  • Audits
  • Catching misfired docker run commands your CI forgot to clean up

Show the Last N Containers#

Terminal window
docker ps -n 5

Shows the latest 5 containers, regardless of whether they’re running or not. Great when you’re trying to track down what just happened.

Just the IDs (For Scripting)#

Terminal window
docker ps -q

Only container IDs. No fluff. Perfect for feeding into other commands:

Terminal window
docker stop $(docker ps -q)

Pro tip: pair with -a if you want all container IDs, not just running ones.

Show Container Sizes#

Terminal window
docker ps -s

Ever wonder why your CI agents are eating 20GB of disk? This command shows both the actual size and the virtual size of each running container. Stopped containers still hold their writable layer, so add -a to size them too:

Terminal window
docker ps -a -s
CONTAINER ID IMAGE SIZE ...
1a2b3c4d5e6f redis 30MB (virtual 150MB)

Good for pruning. Better for avoiding the next disk outage.

Custom Output with --format#

Terminal window
docker ps --format "{{.ID}} {{.Image}} {{.Status}}"

When you’re piping into tools or just hate staring at wide terminal tables, --format gives you control.

Use this with:

  • --no-trunc to avoid chopped-off IDs and commands
  • JSON outputs if you’re feeding this into monitoring scripts

Filter Like a Pro#

Terminal window
docker ps --filter "status=exited"
docker ps --filter "health=unhealthy"
docker ps --filter "ancestor=nginx"

This is where docker ps turns into grep on steroids. Use it to:

  • Track misbehaving containers by health status
  • Find all containers started from a specific image
  • List containers tied to a specific label

Docker Compose? Same Game, Different Commands#

If you’re living in docker-compose land (you rebel), the commands shift a bit:

Terminal window
docker compose ps

Lists containers in the current Compose project. Basically docker ps, but scoped to the docker-compose.yml in your cwd.

Terminal window
docker compose ls

Shows the Compose projects that are running on the machine, with their status and config files. Add -a to include stopped projects:

Terminal window
docker compose ls -a

Great when your team has 12 different Compose stacks lying around like forgotten pizza boxes.

Cleaning Up Exited Containers#

Exited containers are invisible to plain docker ps and still take disk. List their IDs with a status filter and hand them to docker rm:

Terminal window
docker rm $(docker ps -a -q --filter "status=exited")

docker container prune does the same for every stopped container and asks before it deletes.

Moral of the story: Knowing how to see containers is the first step to controlling them.

Corrected on 2026-10-07: docker ps -s and docker compose ls include stopped containers and projects only with -a, checked on Docker Engine 29.7.2 and Compose 5.5.1. An example that relied on the earlier wording was removed.

Takeaway: Don’t Just Run Containers: Own Them#

Listing containers isn’t a junior-level checkbox. It’s foundational. If you can’t tell what’s running, what’s dead, and what’s unhealthy in under 30 seconds, you’re one stray docker run away from production chaos.

So burn these into your muscle memory. Pipe them into your scripts. Alias the long ones. Teach them to your juniors.

And next time you SSH into a box and run docker ps, do it with confidence. You’re not just checking containers. You’re asserting control.


Vladimir Mikhalev

Docker CaptainCNCF AmbassadorIBM Champion

The Verdict — production-tested analysis on YouTube.

The Verdict

Inconvenient truths about shipping in the AI era

Container security, platform engineering, and the agentic shift — tested in production, argued without the hype. The verdict reaches your inbox the moment there's one worth sending.

Related Posts

Same category
  1. 1
    Scheduled Workflows Fail Silently: A GitHub Actions Heartbeat for 122 Repositories
    DevOps & Cloud · GitHub Actions switches off a scheduled workflow after 60 quiet days, with no failed run and no red badge. What watches every schedule, and the watcher.
  2. 2
    Completed Is Not Restored: Kyverno Fail-Open, a Velero Restore and an HTTP 200 That Meant 500
    DevOps & Cloud · Scale Kyverno to zero and its webhooks vanish. A Velero restore said Completed over an empty disk. A 200 carried a 500. Three statuses that reported success.
  3. 3
    Docker Hub Immutable Tags: The Image That Shipped Before It Was Signed
    DevOps & Cloud · Docker Hub immutable tags refused a per-commit tag after the version tags were already out. The image shipped, the run died, and nothing ever signed it.
  4. 4
    Docker Hardened Images Migration: A Healthy Database That Kept Nothing
    DevOps & Cloud · Moving a Compose stack to Docker Hardened Images changes user IDs, paths and tools. On the old mount path, PostgreSQL stayed healthy and kept nothing.

Random Posts

Random
  1. 1
    Configure Exchange Server 2016
    SysAdmin & IT Pro · Step-by-step guide to configure Exchange Server 2019 — mailbox databases, public folders, DNS, certificates, and send/receive connectors.
  2. 2
    Compose Bridge: Docker Compose File In, Kubernetes Manifests Out
    DevOps & Cloud · How Compose Bridge turns compose.yaml into Kubernetes resources, what it generates, how to change the templates, and how to run it as a kubectl plugin.
  3. 3
    What is the Cloud?
    DevOps & Cloud · Explore the history of cloud computing and how SaaS, PaaS, and IaaS models from AWS, Azure, and GCP power today's digital infrastructure.
  4. 4
    Install Jira Using Docker Compose
    Self-Hosting · Learn how to install Jira using Docker Compose with Traefik and Let's Encrypt. Step-by-step guide to self-host Jira securely and efficiently.
Essential Commands for Listing Docker Containers
https://heyvaldemar.com/essential-commands-for-listing-docker-containers/
Author
Vladimir Mikhalev
Published
2024-04-26
Updated
2026-10-07
License
CC BY-NC-SA 4.0