0
0
Dockerdevops~3 mins

Listing containers (docker ps, docker ps -a) - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you want to see which containers are running or have run on your computer. The commands docker ps and docker ps -a help you list these containers so you know their status and details.
When you want to check which containers are currently running on your machine.
When you want to see all containers, including those that have stopped or exited.
When you need to find the container ID or name to stop or remove a container.
When you want to verify if a container started correctly after running a docker run command.
When you want to monitor container uptime and status during development or troubleshooting.
Commands
This command lists all containers that are currently running. It shows useful details like container ID, image, status, and ports.
Terminal
docker ps
Expected OutputExpected
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b7c8f9a1d2e3 nginx:1.23.3 "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 0.0.0.0:8080->80/tcp my-nginx
This command lists all containers on your system, including those that are stopped or exited. It helps you see the full history of containers.
Terminal
docker ps -a
Expected OutputExpected
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b7c8f9a1d2e3 nginx:1.23.3 "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 0.0.0.0:8080->80/tcp my-nginx f4d5e6b7c8a9 redis:7.0 "docker-entrypoint.s…" 2 hours ago Exited (0) 30 minutes ago my-redis
-a - Show all containers, including stopped ones
Key Concept

If you remember nothing else from this pattern, remember: docker ps shows running containers, docker ps -a shows all containers including stopped ones.

Common Mistakes
Running docker ps expecting to see stopped containers.
docker ps only shows running containers, so stopped containers won't appear.
Use docker ps -a to see all containers, including stopped ones.
Not recognizing container names or IDs when managing containers.
Without listing containers, you can't find the correct container to stop or remove.
Always run docker ps or docker ps -a to find container IDs or names before managing them.
Summary
docker ps lists only running containers with their details.
docker ps -a lists all containers, including stopped and exited ones.
Use these commands to find container IDs or names for further management.