Docker stats Command

Docker stats Command

docker stats : Displays container resource usage, including: CPU, memory, network I/O, etc.

Docker stats Syntax

docker stats [OPTIONS] [CONTAINER...]

OPTIONS Description:

  • –all , -a : Show all containers, including non-running ones.
  • –format : Specify the template file for the return value.
  • –no-stream : Show the current state and just exit, no more live updates.
  • –no-trunc : Do not truncate the output.

Docker stats Example

Lists information about all running containers.

docker stats

Output:

apidemos@apidemos:~$  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 Description.

CONTAINER ID and NAME: The container ID and name.

CPU % and MEM %: The percentage of CPU and memory used by the container.

MEM USAGE / LIMIT: The total memory being used by the container and the total amount of memory allowed to be used.

NET I/O: The amount of data sent and received by the container through its network interface.

BLOCK I/O: The amount of data the container is reading from and writing to block devices on the host.

PIDs: The number of processes or threads created by the container.

Realistic information based on IDs or names of containers, etc.

apidemos@apidemos:~$ 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.

apidemos@apidemos:~$ 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 the specified information.

apidemos@apidemos:~$ 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
Like(0)