The “docker stats” command is a powerful tool used in Docker, a popular containerization platform. When you execute the “docker stats” command, it displays a live stream of resource usage statistics for running containers on your system.
Containerization allows you to isolate applications and their dependencies within lightweight, portable containers. Docker provides a way to manage and monitor these containers, and the “docker stats” command is one of the monitoring tools it offers.
When you run the “docker stats” command, it presents a continuously updating table that shows various metrics for each container, including:
- Container ID: A unique identifier for each running container.
- CPU Usage: The percentage of CPU resources being utilized by the container.
- Memory Usage: The amount of memory (RAM) being consumed by the container.
- Network I/O: The amount of incoming and outgoing network traffic for the container.
- Block I/O: The input and output operations being performed by the container on disk.
- PIDs: The number of processes running inside the container.
By default, the “docker stats” command displays statistics for all running containers on the system. However, you can also specify specific container names or IDs as arguments to limit the output to a subset of containers.
The real-time nature of the output allows you to monitor the resource utilization of your containers at a glance. This information is beneficial for troubleshooting, capacity planning, and optimizing resource allocation for your Dockerized applications.
Please note that the “docker stats” command provides a live stream of statistics, and it continues to display data until you manually stop it by pressing Ctrl+C.
docker stats Command Examples
1. Display a live stream for the statistics of all running containers:
# docker stats
2. Display a live stream of statistics for a space-separated list of containers:
# docker stats container_name
3. Change the columns format to display container’s CPU usage percentage:
# docker stats --format ".Name:\t.CPUPerc"
4. Display statistics for all containers (both running and stopped):
# docker stats --all
5. Disable streaming stats and only pull the current stats:
# docker stats --no-stream