Listing All Docker Containers, Including Stopped Ones
To list all Docker containers, including those that are stopped, you can use the docker ps
command with the -a
(or --all
) option.
The basic command to list all containers is:
docker ps -a
This will display a table with information about all the containers on your system, regardless of their current state (running, stopped, or exited).
Here's an example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "nginx -g 'daemon off" 2 hours ago Exited (0) 10 minutes ago web-server
g7h8i9j0k1l2 redis:latest "docker-entrypoint.sโฆ" 3 hours ago Up 2 hours 6379/tcp cache
m3n4o5p6q7r8 ubuntu:20.04 "/bin/bash" 4 hours ago Exited (0) 1 hour ago test-container
In this example, you can see three containers:
web-server
: An Nginx web server that is currently stopped (Exited)cache
: A Redis cache that is currently running (Up)test-container
: An Ubuntu container that is currently stopped (Exited)
The docker ps -a
command provides the following information for each container:
- CONTAINER ID: The unique identifier of the container
- IMAGE: The Docker image used to create the container
- COMMAND: The command used to start the container
- CREATED: The time when the container was created
- STATUS: The current status of the container (running, stopped, or exited)
- PORTS: The network ports exposed by the container
- NAMES: The name assigned to the container
By using the -a
option, you can see all the containers on your system, including those that are not currently running. This can be useful when you need to manage or interact with stopped or exited containers.
Here's a Mermaid diagram that illustrates the process of listing all Docker containers, including stopped ones:
This diagram shows that the docker ps
command without any options will only list the running containers, while the docker ps -a
command will list all containers, including those that are stopped or exited.
By understanding how to list all Docker containers, including stopped ones, you can better manage and interact with your Docker environment, whether you need to inspect, start, stop, or remove specific containers.