docker system命令集合的使用
docker system 目前擁有四個子命令,分別是:
docker system df
docker system events
docker system info
docker system prune
docker system 其中最重要的一個命令就是 docker system prune 命令,清理沒有使用的數(shù)據(jù),包括鏡像數(shù)據(jù),已經(jīng)停止的容器
查看 docker system 幫助
[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
提供Docker整體磁盤使用率的概況,包括鏡像、容器和(本地)volume。所以我們現(xiàn)在隨時都可以查看Docker使用了多少資源。
[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
如果之前的命令展示出 docker 已經(jīng)占用了太多空間,我們會開始清理。有一個包辦一切的命令:
[root@localhost ~]# docker system prune
WARNING! This will remove:
- all stopped containers # 清理停止的容器
- all networks not used by at least one container #清理沒有使用的網(wǎng)絡(luò)
- all dangling images #清理廢棄的鏡像
- all build cache #清理構(gòu)建緩存
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
[root@localhost ~]#
根據(jù)警告信息可知,這個命令會刪除所有關(guān)閉的容器以及dangling鏡像。示例中,含有3個1GB隨機文件的鏡像的名稱被占用了,名稱為:,為dangling鏡像,因此會被刪除。同時,所有的中間鏡像也會被刪除。
更進一步,使用-a選項可以做深度清理。這時我們會看到更加嚴重的WARNING信息:
$ 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
這個命令將清理整個系統(tǒng),并且只會保留真正在使用的鏡像,容器,數(shù)據(jù)卷以及網(wǎng)絡(luò),因此需要格外謹慎。比如,我們不能在生產(chǎn)環(huán)境中運行prune -a命令,因為一些備用鏡像(用于備份,回滾等)有時候需要用到,如果這些鏡像被刪除了,則運行容器時需要重新下載。
此時,所有未綁定容器的鏡像將會被刪除。由于第一次prune命令刪除了所有容器,因此所有鏡像(它們沒有綁定任何容器)都會被刪除。
docker systemc info (docker info)
這個命令的縮寫docker info相信大家都很熟悉
[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 ~]#
詳細的解釋
| 元字符 | 描述 |
|---|---|
| info 等同于 docker info |
查看整個docker系統(tǒng)的信息 例如 docker system info 例如 docker system info | grep Images |
| events 等同于 docker events |
獲取docker系統(tǒng)實時事件,不包括容器內(nèi)的。 例如: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 #包括清理以下的四種,即容器、鏡像、數(shù)據(jù)卷、網(wǎng)絡(luò) – 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 |
到此這篇關(guān)于docker system命令集合的使用的文章就介紹到這了,更多相關(guān)docker system內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信