Docker专栏—Docker常用命令之资源篇

534 阅读2分钟

资源命令

docker stats

显示一个或多个容器资源使用情况统计信息的实时流。

  • 帮助
[root@t32 docker]# docker stats --help

Usage:	docker 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
      --help            Print usage
      --no-stream       Disable streaming stats and only pull the first result
[root@t32 docker]# 
  • 例子
[root@t32 docker]# docker stats 389458e3835f  fc8412329b91

CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
389458e3835f        0.05%               18.77 MiB / 251.6 GiB   0.01%               0 B / 0 B           0 B / 0 B           67
fc8412329b91        0.00%               436 KiB / 251.6 GiB     0.00%               2.82 GB / 156 MB    0 B / 6.19 GB       1

docker system

管理docker系统

  • 帮助
[root@t32 docker]# docker system --help

Usage:	docker system COMMAND

Manage Docker

Options:
      --help   Print usage

Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

dockre system df

显示docker的硬盘使用情况

  • 帮助
[root@t32 docker]# docker system df  --help

Usage:	docker system df [OPTIONS]

Show docker disk usage

Options:
      --help      Print usage
  -v, --verbose   Show detailed information on space usage
  • 例子
[root@t32 docker]# docker system df 
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              16                  12                  4.922 GB            2.678 GB (54%)
Containers          22                  19                  1.46 GB             0 B (0%)
Local Volumes       2                   2                   47.13 MB            0 B (0%)
  • RECLAIMABLE:可回收的磁盘空间
  • SIZE:使用的磁盘空间

docker system events

和docker events用法一样,具体参见我的另外一篇文章Docker专题—Docker常用命令之基础篇

docker system info

和docker info用法一样,具体参见我的另外一篇文章Docker专题—Docker常用命令之基础篇

docker system prune

删除可回收的资源

  • 帮助
[root@t32 docker]# docker system prune --help

Usage:	docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all     Remove all unused images not just dangling ones
  -f, --force   Do not prompt for confirmation
      --help    Print usage
  • 例子
[root@t32 docker]# docker system prune -a 
WARNING! This will remove:
	- all stopped containers
	- all volumes not used by at least one container
	- all networks not used by at least one container
	- all images without at least one container associated to them
Are you sure you want to continue? [y/N] y
Deleted Containers:
fa44aaf111d88862a5eb7718f15b9a4f26b7814f9f77bf03851319acb161d75b
bd1eeaa010500f77398b4dc4437d384f688ac72571dcaf25f1339237abb48548
9d5840153e06906f054d5995c81950793f17425f9db9ed4cef11b05cb5922107

Deleted Images:
untagged: docker.io/centos:latest
untagged: docker.io/rancher/calico-cni:v3.4.0
.....

Total reclaimed space: 2.83 GB
[root@t32 docker]# docker system df 
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              10                  10                  2.092 GB            4.148 MB (0%)
Containers          19                  19                  1.46 GB             0 B (0%)
Local Volumes       2                   2                   47.13 MB            0 B (0%)
[root@t32 docker]#