您当前的位置:首页 > 网站建设 > 网站维护
| php | asp | css | H5 | javascript | Mysql | Dreamweaver | Delphi | 网站维护 | 帝国cms | React | 考试系统 | ajax | jQuery |

docker system命令集合的使用

51自学网 2022-07-04 11:29:55
  网站维护

docker system 目前拥有四个子命令,分别是:

docker system df
docker system events
docker system info
docker system prune

docker system 其中最重要的一个命令就是 docker system prune 命令,清理没有使用的数据,包括镜像数据,已经停止的容器

查看 docker system 帮助

[root@localhost ~]# docker system --helpUsage:  docker system COMMANDManage DockerOptions:      --help   Print usageCommands:  df          Show docker disk usage  events      Get real time events from the server  info        Display system-wide information  prune       Remove unused dataRun 'docker system COMMAND --help' for more information on a command.[root@localhost ~]# 

docker system df

提供Docker整体磁盘使用率的概况,包括镜像、容器和(本地)volume。所以我们现在随时都可以查看Docker使用了多少资源。

[root@localhost ~]# docker system dfTYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLEImages              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

如果之前的命令展示出 docker 已经占用了太多空间,我们会开始清理。有一个包办一切的命令:

[root@localhost ~]# docker system pruneWARNING! This will remove:        - all stopped containers # 清理停止的容器        - all networks not used by at least one container #清理没有使用的网络        - all dangling images #清理废弃的镜像        - all build cache #清理构建缓存Are you sure you want to continue? [y/N] yTotal reclaimed space: 0B[root@localhost ~]# 

根据警告信息可知,这个命令会删除所有关闭的容器以及dangling镜像。示例中,含有3个1GB随机文件的镜像的名称被占用了,名称为:,为dangling镜像,因此会被删除。同时,所有的中间镜像也会被删除。

更进一步,使用-a选项可以做深度清理。这时我们会看到更加严重的WARNING信息:

$ docker system prune -aWARNING! 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 themAre you sure you want to continue? [y/N] yDeleted Images:untagged: test:latestdeleted: sha256:c515ebfa2...deleted: sha256:07302c011...deleted: sha256:37c0c6474...deleted: sha256:5cc2b6bc4...deleted: sha256:b283b9c35...deleted: sha256:8a8b9bd8b...untagged: alpine:latestuntagged: alpine@sha256:58e1a1bb75db1...deleted: sha256:4a415e366...deleted: sha256:23b9c7b43...Total reclaimed space: 2.151GB

这个命令将清理整个系统,并且只会保留真正在使用的镜像,容器,数据卷以及网络,因此需要格外谨慎。比如,我们不能在生产环境中运行prune -a命令,因为一些备用镜像(用于备份,回滚等)有时候需要用到,如果这些镜像被删除了,则运行容器时需要重新下载。

此时,所有未绑定容器的镜像将会被删除。由于第一次prune命令删除了所有容器,因此所有镜像(它们没有绑定任何容器)都会被删除。

docker systemc info (docker info)

这个命令的缩写docker info相信大家都很熟悉

[root@localhost ~]# docker system infoContainers: 6 Running: 6 Paused: 0 Stopped: 0Images: 49Server Version: 17.06.2-ceStorage Driver: overlay Backing Filesystem: xfs Supports d_type: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:  Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2init version: 949e6faSecurity Options: seccomp  Profile: defaultKernel Version: 3.10.0-514.26.2.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 24Total Memory: 31.21GiBName: localhost.localdomainID: YTL2:6RWX:IZK6:X4XC:XKMO:WVXD:LXPR:E5GN:GEJB:WIUX:L5YH:PDFBDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Experimental: falseInsecure Registries: 127.0.0.0/8Registry Mirrors: http://9zkjjecg.mirror.aliyuncs.com/ https://docker.mirrors.ustc.edu.cn/Live Restore Enabled: false[root@localhost ~]# 

详细的解释

元字符 描述
info
等同于 docker info
查看整个docker系统的信息
例如 docker system info
例如 docker system info | grep Images
events
等同于 docker events
获取docker系统实时事件,不包括容器内的。
例如:docker system events
下载地址:
docker prune命令可定时清理不常用数据的实现
Docker使用Prune命令清理none镜像
51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1