Use of docker system Command Set
- 2021-11-10 11:16:27
- OfStack
docker system currently has four subcommands, which are:
docker system df
docker system events
docker system info
docker system prune
One of the most important commands in docker system is the command docker system prune, which cleans up unused data, including mirrored data and stopped containers
View docker system Help
[root@localhost ~]# 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
Run 'docker system COMMAND --help' for more information on a command.
[root@localhost ~]#
docker system df
Provides an overview of the overall disk usage of Docker, including mirroring, containers, and (native) volume. So we can now check how many resources Docker uses at any time.
[root@localhost ~]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 10 6 2.652GB 1.953GB (73%)
Containers 6 6 6.922MB 0B (0%)
Local Volumes 0 0 0B 0B
[root@localhost ~]#
docker system prune
If the previous command shows that docker has taken up too much space, we will start cleaning up. There is a command to arrange 1 cut:
[root@localhost ~]# docker system prune
WARNING! This will remove:
- all stopped containers # Cleaning Stopped Container
- all networks not used by at least one container # Clean up unused networks
- all dangling images # Clean up obsolete images
- all build cache # Clean up the build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
[root@localhost ~]#
According to the warning message, this command will delete all closed containers and dangling images. In the example, the name of the image containing three 1GB random files is occupied, and the name is:, which is an dangling image, so it will be deleted. At the same time, all intermediate images will be deleted.
One step further, use the-a option to do deep cleaning. At this point, we will see more serious WARNING information:
$ 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 Images:
untagged: test:latest
deleted: sha256:c515ebfa2...
deleted: sha256:07302c011...
deleted: sha256:37c0c6474...
deleted: sha256:5cc2b6bc4...
deleted: sha256:b283b9c35...
deleted: sha256:8a8b9bd8b...
untagged: alpine:latest
untagged: alpine@sha256:58e1a1bb75db1...
deleted: sha256:4a415e366...
deleted: sha256:23b9c7b43...
Total reclaimed space: 2.151GB
This command will clean up the entire system and will keep only the images containers data volumes and networks that are actually in use so you need to be extra careful. For example, we can't run the prune-a commands in a production environment, because some spare images (for backup, rollback, etc.) are sometimes needed, and if these images are deleted, they need to be downloaded again when running the container.
At this point, all images of unbound containers will be deleted. Since the first prune command deleted all containers, all images (which are not bound to any containers) will be deleted.
docker systemc info (docker info)
The abbreviation of this command docker info is familiar to everyone
[root@localhost ~]# docker system info
Containers: 6
Running: 6
Paused: 0
Stopped: 0
Images: 49
Server Version: 17.06.2-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.26.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 24
Total Memory: 31.21GiB
Name: localhost.localdomain
ID: YTL2:6RWX:IZK6:X4XC:XKMO:WVXD:LXPR:E5GN:GEJB:WIUX:L5YH:PDFB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
http://9zkjjecg.mirror.aliyuncs.com/
https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false
[root@localhost ~]#
A detailed explanation
元字符 | 描述 |
---|---|
info 等同于 docker info |
查看整个docker系统的信息 例如 docker system info 例如 docker system info | grep Images |
events 等同于 docker events |
获取docker系统实时事件,不包括容器内的。 例如:docker system events �until 1499305500 // 截止到 2017.7.6 01:45:00的操作 例如:docker system events �since 1499305500 // 从 2017.7.6 01:45:00之后的操作 |
df | 整体磁盘的使用情况 例如:docker system df 例如:docker system df -v |
prune | 清理资源,此操作尤其需要注意。 例如:docker system prune #包括清理以下的4种,即容器、镜像、数据卷、网络 � all stopped containers � all volumes not used by at least one container � all networks not used by at least one container � all dangling images 例如:docker system prune -a #包括以下的4种情况,主要和上比较 � 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 |