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 Captain  ·  CNCF Ambassador  ·  IBM 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
    Restore Drills on a Clean Machine — Measured RTO for 47 Stacks, 19 Seconds to 7 Minutes
    DevOps & Cloud · Restore drills that measure RTO on a machine that never ran the stack, 47 templates weekly. Every same-host restore passed. The first clean one answered 500.
  2. 2
    Mutation Testing for Infrastructure Code — 153 Planted Bugs, Four Tests That Could Not Fail
    DevOps & Cloud · Mutation testing for infrastructure code, done by hand across fifteen repositories. 153 planted bugs, and four green tests that could never have failed.
  3. 3
    Docker Health Checks That Cannot Fail — Seventeen Hours Green
    DevOps & Cloud · A Docker health check whose pattern matches the shell running it can never go red. How to find the checks in your fleet that never failed, and prove each one.
  4. 4
    Terraform MCP server GA: the Apply Gate your auditor will ask about
    DevOps & Cloud · HashiCorp's Terraform MCP server is GA and IBM Bob can write production IaC. ENABLE_TF_OPERATIONS separates a safe assistant from autonomous apply.

Random Posts

Random
  1. 1
    Install Exchange Server 2016 on Windows Server 2012 R2
    SysAdmin & IT Pro · Step-by-step guide to install Exchange Server 2016 on Windows Server 2012 R2, including prerequisites, AD setup, and post-installation configuration.
  2. 2
    Install Rocket.Chat Using Docker Compose
    Self-Hosting · Step-by-step guide to install Rocket.Chat on Ubuntu Server using Docker Compose and Traefik with Let's Encrypt SSL. Ideal for secure team communication..
  3. 3
    Simplifying the Transition from Docker Compose to Kubernetes with Compose Bridge
    DevOps & Cloud · Discover how to convert Docker Compose files to Kubernetes manifests using Docker's Compose Bridge. Simplify your migration and deploy applications efficiently.
  4. 4
    Install Nextcloud Using Docker Compose
    Self-Hosting · Complete guide to installing Nextcloud with Docker Compose and Traefik. Learn to deploy your own secure file sharing and collaboration cloud with HTTPS.
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