Listing All Running Docker Containers
To list all running Docker containers, you can use the docker ps
command. This command will display a list of all the containers that are currently running on your Docker host.
Here's how you can use the docker ps
command:
docker ps
This will output a table with the following information for each running container:
- CONTAINER ID: The unique identifier for the container.
- IMAGE: The name of the Docker image that the container was created from.
- COMMAND: The command that the container is running.
- CREATED: The time when the container was created.
- STATUS: The current status of the container (e.g., running, exited).
- PORTS: The network ports that the container is listening on.
- NAMES: The name of the container.
If you want to see all containers, including those that are not running, you can use the -a
or --all
flag:
docker ps -a
This will show you all the containers on your Docker host, regardless of their current status.
Here's an example of what the output might look like:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "nginx -g 'daemon off" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp web-server
f6e5d4c3b2a1 redis:latest "redis-server" 10 minutes ago Up 10 minutes 0.0.0.0:6379->6379/tcp cache
In this example, we can see that there are two running containers: a web server running the nginx
image, and a Redis cache running the redis
image.
To further customize the output of the docker ps
command, you can use the --format
flag to specify the columns you want to display. For example, to show only the container ID and image name, you can use the following command:
docker ps --format "{{.ID}} {{.Image}}"
This will output something like:
a1b2c3d4e5f6 nginx:latest
f6e5d4c3b2a1 redis:latest
Overall, the docker ps
command is a powerful tool for managing and monitoring your Docker containers. By understanding how to use it effectively, you can quickly and easily keep track of the containers running on your Docker host.