The “docker ps” command is used to list the Docker containers that are currently running on your system. It provides an overview of the containers’ status, such as their IDs, names, images, creation time, and resource usage.
Here’s a breakdown of the different aspects and options of the “docker ps” command:
- Listing Running Containers: By default, running “docker ps” without any additional options will display a list of running containers on your system. The output includes information such as the container ID, image used to create the container, container name, and the command being executed within the container.
- Display All Containers (Including Stopped Ones): If you want to see all containers, including the ones that have stopped, you can use the “-a” or “–all” option. This will show a comprehensive list of both running and stopped containers.
- Customize Output Format: The “docker ps” command provides several options to customize the output format. For example, you can use the “–format” flag to specify a Go template to control the output format. This allows you to display only specific information about the containers, such as IDs or names, in a desired format.
- Filter Containers: You can filter the container list based on different criteria. For instance, you can use the “–filter” or “-f” flag followed by a key-value pair to filter containers based on specific attributes like the container’s status, label, or network. This helps you narrow down the list and find containers that meet specific criteria.
- Display Size Information: To include the size information of containers in the output, you can use the “–size” option. This will show the disk usage of each container, including the total size of the container’s writable layers.
The “docker ps” command is a powerful tool for managing and monitoring Docker containers. It allows you to quickly view the running containers on your system, check their statuses, and gather essential information about them. By leveraging the various options available, you can customize the output to suit your specific needs and filter the list based on different criteria.
Remember to run the “docker ps” command with appropriate permissions, such as using sudo or being a member of the Docker group, depending on your system configuration.
docker ps Command Examples
1. List currently running docker containers:
# docker ps
2. List all docker containers (running and stopped):
# docker ps --all
3. Show the latest created container (includes all states):
# docker ps --latest
4. Filter containers that contain a substring in their name:
# docker ps --filter="name=name"
5. Filter containers that share a given image as an ancestor:
# docker ps --filter "ancestor=image:tag"
6. Filter containers by exit status code:
# docker ps --all --filter="exited=code"
7. Filter containers by status (created, running, removing, paused, exited and dead):
# docker ps --filter="status=status"
8. Filter containers that mount a specific volume or have a volume mounted in a specific path:
# docker ps --filter="volume=/path/to/directory" --format "table .ID\t.Image\t.Names\t.Mounts"