Exploring Advanced Listing Options
While the basic docker ps
command provides a wealth of information about your running containers, Docker offers several advanced options to help you dig deeper and gain more insights into your Docker environment.
Listing Containers by Status
In addition to listing running containers, you can also list containers by their status. For example, to list all containers that are currently exited or stopped, you can use the following command:
docker ps -a --filter "status=exited"
You can also list containers by other statuses, such as "created", "restarting", or "paused".
Listing Containers by Label
Docker allows you to assign labels to your containers, which can be useful for organizing and filtering your containers. To list containers by a specific label, you can use the --filter
option:
docker ps --filter "label=my-label=value"
This will list all containers that have the label "my-label" with the value "value".
Listing Containers by Resource Usage
To get information about the resource usage of your containers, you can use the docker stats
command. This command will display real-time statistics about CPU, memory, network, and block I/O usage for each running container.
docker stats
You can also filter the output of docker stats
using the same techniques as docker ps
, such as by container name or label.
If you need to programmatically process the output of docker ps
, you can use the --format
option to output the container information in JSON format. This can be useful for integrating Docker container management into your own scripts or applications.
docker ps --format '{{json .}}'
By exploring these advanced listing options, you can gain a deeper understanding of your Docker containers and effectively manage your Docker environment.