Docker stats command
docker statsThe command is used to display real-time resource usage of Docker containers, including CPU, memory, network I/O, and block I/O.
docker statsSimilar to the one in Linux systemstopcommand, but it is specifically targeted at Docker containers. Throughdocker stats, users can monitor container resource usage, helping optimize performance and troubleshoot issues.
Syntax
docker stats [OPTIONS] [CONTAINER...]
OPTIONS description:
--all , -a :Show all containers, including those not running.
--format :Template file that specifies the return value.
--no-stream :Displays the current status and then exits immediately, no longer updating in real-time.
--no-trunc :Do not truncate output.
Display resource usage of all running containers:
docker stats
Display resource usage of a specified container:
docker stats my_container
Display resource usage of all containers (including non-running containers):
docker stats --all
Display data only once instead of continuously refreshing:
docker stats --no-stream
Output using a custom format:
docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
Example
List information for all running containers.
example@example:~$ docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS b95a83497c91 awesome_brattain 0.28% 5.629MiB / 1.952GiB 0.28% 916B / 0B 147kB / 0B 9 67b2525d8ad1 foobar 0.00% 1.727MiB / 1.952GiB 0.09% 2.48kB / 0B 4.11MB / 0B 2 e5c383697914 test-1951.1.kay7x1lh1twk9c0oig50sd5tr 0.00% 196KiB / 1.952GiB 0.01% 71.2kB / 0B 770kB / 0B 1 4bda148efbc0 random.1.vnc8on831idyr42slu578u3cr 0.00% 1.672MiB / 1.952GiB 0.08% 110kB / 0B 578kB / 0B 2
Output detailed introduction:
CONTAINER ID and NAME:Container ID and name.
CPU % and MEM %:The percentage of CPU and memory used by the container.
MEM USAGE / LIMIT:The total memory the container is using, as well as the total memory it is allowed to use.
NET I/O:The amount of data the container sends and receives through its network interface.
BLOCK I/O:The amount of data the container reads from and writes to block devices on the host.
PIDs:Number of processes or threads created by the container.
Display information based on the container ID or name:
example@example:~$ docker stats awesome_brattain 67b2525d8ad1 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS b95a83497c91 awesome_brattain 0.28% 5.629MiB / 1.952GiB 0.28% 916B / 0B 147kB / 0B 9 67b2525d8ad1 foobar 0.00% 1.727MiB / 1.952GiB 0.09% 2.48kB / 0B 4.11MB / 0B 2
Output in JSON format:
example@example:~$ docker stats nginx --no-stream --format "{{ json . }}"
{"BlockIO":"0B / 13.3kB","CPUPerc":"0.03%","Container":"nginx","ID":"ed37317fbf42","MemPerc":"0.24%","MemUsage":"2.352MiB / 982.5MiB","Name":"nginx","NetIO":"539kB / 606kB","PIDs":"2"}
Output specified information:
example@example:~$ docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" fervent_panini 5acfcb1b4fd1 drunk_visvesvaraya big_heisenberg
{"BlockIO":"0B / 13.3kB","CPUPerc":"0.03%","Container":"nginx","ID":"ed37317fbf42","MemPerc":"0.24%","MemUsage":"2.352MiB / 982.5MiB","Name":"nginx","NetIO":"539kB / 606kB","PIDs":"2"}
CONTAINER CPU % MEM USAGE / LIMIT
fervent_panini 0.00% 56KiB / 15.57GiB
5acfcb1b4fd1 0.07% 32.86MiB / 15.57GiB
drunk_visvesvaraya 0.00% 0B / 0B
big_heisenberg 0.00% 0B / 0B
Common Scenarios
- Real-time monitoring: View container resource usage in real time for performance monitoring and optimization.
- Troubleshooting: When problems occur in containers, check resource usage to help identify the root cause.
- Resource management: Monitor container resource usage to ensure reasonable resource allocation and avoid resource waste or bottlenecks.
docker statsThe command is a powerful tool for real-time monitoring of Docker container resource usage. Through this command, users can obtain detailed information about container CPU, memory, network I/O, and block I/O, helping with performance optimization, troubleshooting, and resource management.
other extensions