How to List Containers in Docker
TLDR
Use docker ps
to list running containers, and docker ps -a
to see all containers, including those that have exited. Add filters or formatting for more targeted results.
Prerequisites
- Docker installed (any recent version)
- Terminal access
Listing Running Containers
To see all containers currently running on your system, use:
# List running containers
docker ps
This shows container IDs, names, images, and status. It's helpful for quickly checking what's active.
Listing All Containers (Including Stopped)
If you want to see containers that have exited or stopped, add the -a
flag:
# List all containers, including stopped ones
docker ps -a
This is useful for troubleshooting or cleaning up old containers.
Filtering and Formatting Output
You can filter containers by status or name, and format the output for scripts or reports.
# Show only exited containers
docker ps -a --filter status=exited
# Show containers with a specific name
docker ps -a --filter "name=webapp"
# Custom columns for easier reading
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"
Next Steps
Try combining these commands with docker stop
, docker start
, or docker rm
to manage your containers more efficiently.
Good luck with your project!
Published: 2024-01-28|Last updated: 2024-01-28T09:00:00Z
Found an issue?