Listing Running Docker Containers
To list the running Docker containers on your system, you can use the docker ps
command. This command will display information about the currently running containers, including their container ID, image, command, creation time, status, and ports.
Here's the basic syntax for the docker ps
command:
docker ps [options]
Here are some common options you can use with docker ps
:
-a
: List all containers (running and stopped)-q
: Only display the numeric IDs of the containers-n=<number>
: List the most recent<number>
of containers-f <filter>
: Filter output based on conditions provided
For example, to list all running Docker containers, you can use the following command:
docker ps
This will output something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "nginx -g 'daemon off" 10 minutes ago Up 10 minutes 0.0.0.0:80->80/tcp web-server
g7h8i9j0k1l2 redis:latest "docker-entrypoint.s" 15 minutes ago Up 15 minutes 0.0.0.0:6379->6379/tcp redis-cache
This output shows that there are two running containers: a web server running the nginx
image and a Redis cache running the redis
image.
If you want to list all containers, both running and stopped, you can use the -a
option:
docker ps -a
This will show you all the containers on your system, regardless of their current status.
You can also filter the output using the -f
option. For example, to list only the containers that are currently running, you can use the following command:
docker ps -f "status=running"
This will only show the containers that are currently in the "running" state.
Overall, the docker ps
command is a powerful tool for managing and monitoring your Docker containers. By using the various options, you can customize the output to suit your needs and quickly get an overview of the containers running on your system.