When working with Docker, it’s essential to know how to view your running and stopped containers. Whether you’re debugging, managing resources, or reviewing deployments, Docker provides simple commands to list container details.
In this post, you’ll learn how to:
- List running Docker containers
- Show all containers (including stopped ones)
- View specific container details using formatting and filters
✅ List Running Containers
To see only currently running containers, use:
docker ps
📋 Output Example:
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
e8d12345a1f3 nginx "nginx -g 'daemon of…" Up 10 minutes 80/tcp webserver
This shows:
- Container ID
- Image used
- Status (e.g., Up, Exited)
- Exposed ports
- Name assigned to the container
🕵️ Show All Containers (Running + Stopped)
To view all containers, including those that have exited:
docker ps -a
This is helpful when you’re trying to:
- Restart a stopped container
- Remove old containers
- Debug container failures
🧹 Show Only Recently Created Containers
Need to check the last few containers? Use the --latest
or --last
options:
docker ps -l # Shows the most recently created container
docker ps -n 5 # Shows the last 5 containers
🧰 Use Filters to Narrow Down the List
You can filter containers by status, name, or label:
docker ps -a --filter "status=exited"
docker ps --filter "name=web"
🧠 Other Useful Filters:
status=running
ancestor=image-name
label=your-label
🧾 Customize Output with --format
Tailor the output to your needs using Go templating:
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}"
🔍 Example Output:
CONTAINER ID IMAGE STATUS
e8d12345a1f3 nginx Up 10 minutes
📌 Summary of Commands
Task | Command |
---|---|
List running containers | docker ps |
List all containers | docker ps -a |
Most recent container | docker ps -l |
Last N containers | docker ps -n N |
Filter by name/status/etc. | docker ps --filter |
Format output | docker ps --format |
📝 Conclusion
Knowing how to list Docker containers is a foundational skill in working with containers effectively. Whether you need to restart, remove, or inspect containers, these commands give you full visibility into what’s running on your system.