有时候好奇容器的运行占了多少内存和CPU,搜索了一下,找到查看的方法。

命令(docker stats --no-stream)输出:

[root@VM-4-11-centos ~]# docker stats --no-stream
CONTAINER ID   NAME          CPU %     MEM USAGE / LIMIT     MEM %     NET I/O          BLOCK I/O         PIDS
1d20d43f3040   vaultwarden   0.00%     13.68MiB / 1.795GiB   0.74%     45.7kB / 429kB   4.23MB / 0B       10
ffb5b5e06156   alist         0.00%     26.34MiB / 1.795GiB   1.43%     567kB / 1.63MB   91.2MB / 8.19kB   6

命令(docker stats)输出,用Ctrl + C退出:

2023-11-05T06:52:10.png

docker stats用法:

[root@VM-4-11-centos ~]# docker stats --help

Usage:  docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics

Aliases:
  docker container stats, docker stats

Options:
  -a, --all             Show all containers (default shows just running)
      --format string   Format output using a custom template:
                        'table':            Print output in table format with column headers (default)
                        'table TEMPLATE':   Print output in table format using the given Go template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more information about
                        formatting output with templates
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output