经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
docker system命令集合的使用
来源:jb51  时间:2021/10/25 17:07:07  对本文有异议

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

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

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

查看 docker system 帮助

  1. [root@localhost ~]# docker system --help
  2.  
  3. Usage: docker system COMMAND
  4.  
  5. Manage Docker
  6.  
  7. Options:
  8. --help Print usage
  9.  
  10. Commands:
  11. df Show docker disk usage
  12. events Get real time events from the server
  13. info Display system-wide information
  14. prune Remove unused data
  15.  
  16. Run 'docker system COMMAND --help' for more information on a command.
  17. [root@localhost ~]#
  18.  

docker system df

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

  1. [root@localhost ~]# docker system df
  2. TYPE TOTAL ACTIVE SIZE RECLAIMABLE
  3. Images 10 6 2.652GB 1.953GB (73%)
  4. Containers 6 6 6.922MB 0B (0%)
  5. Local Volumes 0 0 0B 0B
  6. [root@localhost ~]#
  7.  

docker system prune

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

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

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

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

  1. $ docker system prune -a
  2. WARNING! This will remove:
  3. - all stopped containers
  4. - all volumes not used by at least one container
  5. - all networks not used by at least one container
  6. - all images without at least one container associated to them
  7. Are you sure you want to continue? [y/N] y
  8. Deleted Images:
  9. untagged: test:latest
  10. deleted: sha256:c515ebfa2...
  11. deleted: sha256:07302c011...
  12. deleted: sha256:37c0c6474...
  13. deleted: sha256:5cc2b6bc4...
  14. deleted: sha256:b283b9c35...
  15. deleted: sha256:8a8b9bd8b...
  16. untagged: alpine:latest
  17. untagged: alpine@sha256:58e1a1bb75db1...
  18. deleted: sha256:4a415e366...
  19. deleted: sha256:23b9c7b43...
  20. Total reclaimed space: 2.151GB

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

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

docker systemc info (docker info)

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

  1. [root@localhost ~]# docker system info
  2. Containers: 6
  3. Running: 6
  4. Paused: 0
  5. Stopped: 0
  6. Images: 49
  7. Server Version: 17.06.2-ce
  8. Storage Driver: overlay
  9. Backing Filesystem: xfs
  10. Supports d_type: true
  11. Logging Driver: json-file
  12. Cgroup Driver: cgroupfs
  13. Plugins:
  14. Volume: local
  15. Network: bridge host macvlan null overlay
  16. Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
  17. Swarm: inactive
  18. Runtimes: runc
  19. Default Runtime: runc
  20. Init Binary: docker-init
  21. containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
  22. runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
  23. init version: 949e6fa
  24. Security Options:
  25. seccomp
  26. Profile: default
  27. Kernel Version: 3.10.0-514.26.2.el7.x86_64
  28. Operating System: CentOS Linux 7 (Core)
  29. OSType: linux
  30. Architecture: x86_64
  31. CPUs: 24
  32. Total Memory: 31.21GiB
  33. Name: localhost.localdomain
  34. ID: YTL2:6RWX:IZK6:X4XC:XKMO:WVXD:LXPR:E5GN:GEJB:WIUX:L5YH:PDFB
  35. Docker Root Dir: /var/lib/docker
  36. Debug Mode (client): false
  37. Debug Mode (server): false
  38. Registry: https://index.docker.io/v1/
  39. Experimental: false
  40. Insecure Registries:
  41. 127.0.0.0/8
  42. Registry Mirrors:
  43. http://9zkjjecg.mirror.aliyuncs.com/
  44. https://docker.mirrors.ustc.edu.cn/
  45. Live Restore Enabled: false
  46.  
  47. [root@localhost ~]#
  48.  

详细的解释

元字符 描述
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
#包括清理以下的四种,即容器、镜像、数据卷、网络
– 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
#包括以下的四种情况,主要和上比较
– 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

到此这篇关于docker system命令集合的使用的文章就介绍到这了,更多相关docker system内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号