How to List Containers in Docker

Docker containers are the building blocks of modern containerized applications. Whether you’re debugging an issue, monitoring your app, or managing system resources, knowing how to list Docker containers is essential for any developer or DevOps engineer.

In this post, we’ll cover how to list running, stopped, and all containers using simple Docker commands — along with a few useful options to make your workflow smoother.


🐳 Basic Command to List Running Containers

To see all currently running containers:

docker ps

This will output a table with useful information like:

  • Container ID
  • Image used
  • Command executed
  • Status (Up X minutes)
  • Ports exposed
  • Container name

📋 List All Containers (Running + Stopped)

To include stopped, exited, and created containers in the list:

docker ps -a

This is helpful when you want to inspect containers that have exited or failed.


🔎 Filter Containers

Docker allows you to filter the output based on criteria like status, name, or container ID.

Example: List only exited containers

docker ps -a --filter "status=exited"

Example: List container with a specific name

docker ps -a --filter "name=my-app"

🧾 Show Only Container IDs

If you want to get just the container IDs (useful in scripts):

docker ps -q

Combine it with -a to include all:

docker ps -aq

📦 Format the Output

Use the --format flag to customize the output with Go-style templates:

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"

This can make the output easier to read or script against.


🧠 Summary of Useful Commands

TaskCommand
List running containersdocker ps
List all containersdocker ps -a
List only container IDsdocker ps -q
Filter by statusdocker ps -a --filter "status=exited"
Filter by namedocker ps -a --filter "name=app"
Custom outputdocker ps --format

🚀 Bonus Tip: Clean Up Stopped Containers

To list and remove all stopped containers:

docker container prune

This will prompt for confirmation before removing exited containers to free up system resources.


🧭 Conclusion

Understanding how to list and filter Docker containers is a key skill for managing your containerized environment effectively. Whether you’re troubleshooting, cleaning up, or monitoring, these commands will help you stay in control of your Docker workflow.


Tip: Make these commands part of your daily dev/ops routine or integrate them into scripts for automation.

Sharing Is Caring:

Leave a Comment