Docker stats Command
docker stats The command is used to display real-time resource usage of Docker containers, including CPU, memory, network I/O, and block I/O.
docker stats Similar to the command in Linux systems, top this command is specifically designed for Docker containers. Through it docker stats, users can monitor container resource usage, helping optimize performance and troubleshoot.
Syntax
docker stats [OPTIONS] [CONTAINER...]
OPTIONS description:
-
--all , -a :Show all containers, including those not running.
-
--format :Specify a template file for the returned values.
-
--no-stream :Display the current status and exit directly, without further real-time updates.
-
--no-trunc :Do not truncate the output.
Show the resource usage of all running containers:
docker stats
Show the resource usage of a specified container:
docker stats my_container
Show the resource usage of all containers (including those not running):
docker stats --all
Show 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 of all running containers.
runoob@runoob:~$ 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 details:
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 currently used by the container, and the total amount of memory allowed.
NET I/O: The amount of data sent and received by the container through its network interface.
BLOCK I/O: The amount of data read from and written to block devices on the host by the container.
PIDs: The number of processes or threads created by the container.
Display information by container ID or name:
runoob@runoob:~$ 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:
runoob@runoob:~$ 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:
runoob@runoob:~$ 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 a container has problems, check resource usage to help identify the root cause.
- Resource management: Monitor container resource usage to ensure reasonable resource allocation and avoid waste or bottlenecks.
docker stats The command is a powerful tool for monitoring Docker container resource usage in real time. Through it, users can obtain detailed information about a container's CPU, memory, network I/O, and block I/O, helping with performance optimization, troubleshooting, and resource management.
Docker Command Reference