docker container statsでリソース使用状況を確認する方法
現在稼働しているコンテナや停止しているコンテナのリソース使用状況を確認するにはdocker container statsコマンドを実行します。
コマンドの説明
$ docker container stats --help Usage: docker container stats [OPTIONS] [CONTAINER...] Display a live stream of container(s) resource usage statistics Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --no-stream Disable streaming stats and only pull the first result --no-trunc Do not truncate output
実行例
$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 1d622ef86b13 3 days ago 73.9MB centos latest 470671670cac 3 months ago 237MB centos 7.7.1908 08d05d1d5859 5 months ago 204MB $ docker container run -itd --name test01 centos:latest /bin/bash d943d2491c5bc0c846b166d5a55b345efed2a3f75e24a8b314438560a2506f11 $ docker container run -itd --name test02 ubuntu:latest /bin/bash f5cb7624d31acf4ad13797efc5ee242df02acb374c855e36eb0dbde99818b660 $ docker container stats --no-stream CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS f5cb7624d31a test02 0.00% 540KiB / 2.779GiB 0.02% 726B / 0B 0B / 0B 1 d943d2491c5b test01 0.00% 524KiB / 2.779GiB 0.02% 1.31kB / 0B 0B / 0B 1
表示する項目を指定する場合
- .ID:コンテナID
- .Container:コンテナ名、またはコンテナID
- .Name:コンテナ名
- .CPUPerc:CPUパーセンテージ
- .MemUsage:メモリ使用量
- .MemPerc:メモリパーセンテージ
- .NetIO:ネットワークIO
- .BlockIO:ディスクIO
- .PIDs:PID番号
$ docker container stats --no-stream --format "table {{.ID}}\t{{.Name}}\t{{.MemPerc}}" CONTAINER ID NAME MEM % f5cb7624d31a test02 0.02% d943d2491c5b test01 0.02%