Docker 鍨冨溇鍥炴敹鏈哄埗琛ュ厖
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker 鍨冨溇鍥炴敹鏈哄埗琛ュ厖相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/pru' title='pru'>pru
dock share strong 澶у皬 ESS 鍙傛暟 code run 浣滆€咃細寮犻瀵?鏃堕棿锛?020-07-19
w x锛歽18163201
鎴戜滑鍦ㄤ箣鍓嶇殑鏂囩珷閲岄潰璁茶繃Docker 鍨冨溇鍥炴敹鏈哄埗閲岄潰绠€鍗曠殑浠嬬粛浜嗕笅docker * prune
鍛戒护锛屼粖澶╂垜浠潵璇︾粏鐨勮В璇讳笅鏈€鍚庝竴涓?code>docker system prune
鎸囦护,瑙h杩欎釜鍛戒护涔嬪墠鎴戜滑鍏堟潵浜嗚В涓?code>docker system df
docker system df
姝ゅ弬鏁拌鍦?client 鍜?service 绔殑鐗堟湰锛?.25 鐗堟湰浠ヤ笂鎵嶈兘浣跨敤
鏄仛浠€涔堢殑锛?/h3>
杩欎釜鍛戒护鏄緭鍑?Docker 鍦ㄥ涓绘満涓婅祫婧愮殑浣跨敤鎯呭喌銆傚彲浠ユ煡鐪嬮暅鍍忓崰鐢ㄧ┖闂村ぇ灏忥紝瀹瑰櫒鍗犵敤绌洪棿澶у皬锛屾湰鍦扮殑volume 鍜?build 缂撳瓨鐨勫ぇ灏?/p>
涓句緥浣跨敤
鍒涘缓妯℃嫙鐜
# docker pull centos:7.6.1810
# docker pull busybox
# docker pull sellbot:20200617
# docker pull sellbot:20200614
# docker pull sellbot:20200613
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200716 f363f6d1f3f5 3 days ago 544MB
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200714 3b4aa15b779d 4 days ago 544MB
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200713 1f7133d6f068 6 days ago 544MB
busybox latest c7c37e472d31 2 weeks ago 1.22MB
centos 7.6.1810 f1cb7c7d58b7 16 months ago 202MB
# docker run -id --name test centos:7.6.1810 /bin/bash -c "dd if=/dev/zero of=/tmp/1.txt bs=10000 count=2000 && sleep 300 "
# docker run -id busybox /bin/sh -c "/bin/sleep 36000"
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2fa31af4348 centos:7.6.1810 "/bin/bash -c 鈥榙d if鈥? About a minute ago Up About a minute test
7bbaea0e2ded busybox "/bin/sh -c 鈥?bin/sl鈥? 2 minutes ago Up 2 minutes clever_rubin
鐒跺悗浣跨敤鍛戒护鏌ョ湅纾佺洏鐨勪娇鐢ㄦ儏鍐?
# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 5 2 797.9MB 595MB (74%)
Containers 5 1 20MB 20MB (100%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
濡傛灉浠€涔堝弬鏁颁笉鍔犺繖鏄剧ず鏁版嵁鐨勬憳瑕佷俊鎭紝鏉ヨВ閲婁笅姣忓垪鐨勫惈涔夛細
1, Type: 鏄剧ず鍗犵敤纾佺洏绌洪棿鐨勭被鍨?/p>
2, Total锛?/strong> 褰撳墠绫诲瀷鐨勬€绘暟閲忥紝姣斿鍦ㄦ垜浠繖涓幆澧冧竴鍏辨湁 5 涓暅鍍忥紝
3, ACTIVE: 澶勪簬娲诲姩涓殑锛屽綋鍓嶇幆澧冧腑鏈変袱涓暅鍍忔鍦ㄤ娇鐢紝
4, SIZE锛氬綋鍓嶉暅鍍忥紝瀹瑰櫒鍗犵敤纾佺洏鐨勫ぇ灏忥紝
5锛?strong>RECLAIMABLE锛氬彲鍥炴敹锛屽彲浠ヨ閲婃斁鐨勶紝鐧惧垎姣斿氨鏄? RECLAIMABLE/SIZE 鐨勫ぇ灏忋€?/p>
鎴戜滑鍙互鏌ョ湅涓嬫瘡涓€椤圭殑璇︾粏淇℃伅
# docker system df -v
Images space usage:
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200716 f363f6d1f3f5 3 days ago 543.9MB 518.4MB 25.51MB 0
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200714 3b4aa15b779d 4 days ago 543.9MB 518.4MB 25.51MB 0
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200713 1f7133d6f068 6 days ago 543.9MB 518.4MB 25.51MB 0
busybox latest c7c37e472d31 2 weeks ago 1.224MB 0B 1.224MB 4
centos 7.6.1810 f1cb7c7d58b7 16 months ago 201.8MB 0B 201.8MB 1
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
b2fa31af4348 centos:7.6.1810 "/bin/bash -c 鈥榙d if鈥? 0 20MB 12 minutes ago Exited (0) 7 minutes ago test
7bbaea0e2ded busybox "/bin/sh -c 鈥?bin/sl鈥? 0 0B 12 minutes ago Up 12 minutes clever_rubin
ed33045b3f09 busybox "/bin/sh -c /bin/sle鈥? 0 0B 13 minutes ago Created zen_turing
fba6d39f9b6a busybox "/bin/sh -c /bin/sle鈥? 0 0B 13 minutes ago Exited (1) 13 minutes ago pensive_lederberg
6c2e7a0b4e7a busybox "sh" 0 18B 14 minutes ago Exited (0) 14 minutes ago priceless_mirzakhani
Local Volumes space usage:
VOLUME NAME LINKS SIZE
Build cache usage: 0B
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
鎴戜滑鍙互鐪嬪埌褰撴垜浠坊鍔犱簡-v
閫夐」涔嬪悗灏辫兘鐪嬪埌鏇村鐨勪俊鎭簡锛岀浉淇″枩娆㈣瀵熺殑鎮ㄤ竴瀹氬彂鐜颁簡鍦?images 杩欎竴鍒楁湁涓€涓湁鎰忔€濈殑鐜拌薄锛屽氨鏄?SIZE = SHARED SIZE + UNIQUE SIZE
鎴戜滑鏉ュ垎寮€浠嬬粛姣忎竴涓〃鏍奸噷闈㈡瘡涓€鍒楃殑鍚箟
Images space usage:锛?/p>
- REPOSITORY锛?闀滃儚鍚嶇О锛岀敱 浠撳簱鍦板潃/瀛樻斁绌洪棿/闀滃儚鍚嶇О 缁勬垚
- TAG锛?褰撳墠涓€涓暅鍍忕殑 tag锛岀敤鏉ュ尯鍒嗗悓涓€涓暅鍍忕殑涓嶅悓鐗堟湰
- IMAGE ID锛?闀滃儚 ID锛岀敤鏉ュ尯鍒槸鍚︿负鍚屼竴涓暅鍍?鍖呮嫭鐗堟湰)
- CREATE锛?褰撳墠杩欎釜闀滃儚鐨勫垱寤烘椂闂达紝鍙互鐞嗚В涓烘瀯寤烘椂闂?/li>
- SIZE锛?褰撳墠杩欎釜闀滃儚鐨勫ぇ灏?/li>
- SHARED SIZE锛?鍏变韩灞傜殑澶у皬锛屾垜浠兘鐭ラ亾 Docker 鏄垎灞傚瓨鍌ㄧ殑锛岀浉鍚屽眰鍙瓨鍌ㄤ竴浠?/li>
- UNIQUE SIZE锛氬尯鍒簬鍏朵粬闀滃儚鐨勪笉鍚屽眰鐨勫ぇ灏?/li>
- CONTAINERS锛氬綋鍓嶆湁鍑犱釜瀹瑰櫒鏄熀浜庤繖涓暅鍍忓惎鍔ㄧ殑銆傞暅鍍忔槸鍚﹁兘琚竻鐞嗕緷璧栦簬杩欎釜
Containers space usage:
- CONTAINER ID锛?瀹瑰櫒 ID
- IMAGE锛?瀹瑰櫒渚濊禆浜庨偅涓暅鍍忓惎鍔ㄧ殑
- COMMAND锛?瀹瑰櫒鐨勫惎鍔ㄥ懡浠ゆ槸浠€涔?/li>
- LOCAL VOLUMES锛?VOLUME 鐨勬暟閲?/li>
- SIZE锛?褰撳墠瀹瑰櫒鐨勫ぇ灏忥紝鎸囩殑鏄彲鍐欏眰鐨勫ぇ灏忥紝骞朵笉鍖呭惈闀滃儚鐨勫ぇ灏?/li>
- CREATED锛?鍒涘缓鏃堕棿
- STATUS锛氬綋鍓嶅鍣ㄧ殑鐘舵€?/li>
- NAMES锛氬綋鍓嶅鍣ㄧ殑鍚嶇О
Local Volumes space usage:
- VOLUME NAME锛?鍗风殑鍚嶇О
- LINKS锛?/li>
- SIZE锛氬ぇ灏?/li>
Build cache usage: 0B
鍦ㄦ垜浠繖涓緥瀛愰噷闈㈠彧鏈?images 鍜?containers 鏈夊ぇ灏忥紝鏄洜涓烘垜浠病鏈?build 杩囦换浣曢暅鍍忥紝涔熸病鏈夋妸瀹瑰櫒鐨勬椂鍊欐寕杞芥暟鎹嵎
娉ㄦ剰锛?/strong>
杩欎釜鏁版嵁鍗峰苟涓嶆槸-v 鎸囧畾鐨勬暟鎹嵎锛岃€屾槸鎴戜滑鍦ㄦ瀯寤?Dockerfile 鐨勬椂鍊欏啓鐨?VOLUME
鎴戜滑涓嬮潰鏉ュ仛涓疄楠岋紝鎶?VOLUME 寮勫嚭鏉?/p>
FROM centos:7.6.1810
MAINTAINER zhangshoufu(wx:y18163201)
VOLUME /test/data
鏋勫缓 Docker 闀滃儚
# docker build . -t centos:test_volume -f Dockerfile
# docker images | grep volume
centos test_volume 4c3708d6ffdd 16 seconds ago 202MB
鍚姩
# docker run -id --name test-volume-size -v /tmp/test:/test centos:test_volume /bin/bash -c "dd if=/dev/zero of=/test/data/1.txt bs=10000 count=2000 && sleep 300 "
鏌ョ湅
# docker system df -v | grep -A 3 "VOLUME NAME"
VOLUME NAME LINKS SIZE
c72d1b4b1e06d564e6d2ecb19de0daddbfbfa322a1b7545b5b1f8b418a2ecb46 1 20MB
鍒版鎴戜滑灏辩粰 Docker system df 鍛戒护璁茶В瀹屾垚浜嗭紝鐭ラ亾杩欎簺淇℃伅锛屾垜浠嚜瀹氫箟鐩戞帶鐨勬椂鍊欏氨鑳借幏鍙栧埌涓€浜涚壒瀹氱殑鍊硷紝
docker system prune 鍒犻櫎鏈娇鐢ㄧ殑鏁版嵁鍗?/h2>
瀹冭兘鍋氫粈涔?/h3>
瀹冭兘鍒犻櫎鎵€鏈夋湭浣跨敤鐨勫鍣紝缃戠粶锛岄暅鍍?鎮┖鍜屾湭寮曠敤)锛屼互鍙婂嵎
涓嶅姞鍙傛暟浣跨敤瀹冪湅鐪嬫槸浠€涔堟晥鏋?/p>
# docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
579f5e4e70638daa21e0b781bf3c394798df9bd70ceff0ba970d574961c74a4c
f9725e158430855bf5e77ec04b66f6edb7eb59c24bd122457ff7a167381e7599
b2fa31af4348519fa4cdd8270a08498b6c771ece51bc14b3caccacdfd3ad671b
ed33045b3f09eb3c245e1d49214420a8cd0e1a594a85c2323112a77d6006590c
fba6d39f9b6a022472bd9c0083972dcb220a946924be8727a94b89f1a419872c
6c2e7a0b4e7a0517970c465b4b53af8b630fe3255ddab11fa1fb2144cb540d3f
Total reclaimed space: 20MB
鐒跺悗鎴戜滑 docker system df -v 鐪嬩笅缁撴灉
# docker system df -v
Images space usage:
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
centos test_volume 4c3708d6ffdd 9 minutes ago 201.8MB 201.8MB 0B 0
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200716 f363f6d1f3f5 3 days ago 543.9MB 518.4MB 25.51MB 0
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200714 3b4aa15b779d 5 days ago 543.9MB 518.4MB 25.51MB 0
registry.cn-hangzhou.aliyuncs.com/smb/sellbot 20200713 1f7133d6f068 6 days ago 543.9MB 518.4MB 25.51MB 0
busybox latest c7c37e472d31 2 weeks ago 1.224MB 0B 1.224MB 1
centos 7.6.1810 f1cb7c7d58b7 16 months ago 201.8MB 201.8MB 0B 0
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
7bbaea0e2ded busybox "/bin/sh -c 鈥?bin/sl鈥? 0 0B 3 hours ago Up 3 hours clever_rubin
Local Volumes space usage:
VOLUME NAME LINKS SIZE
c72d1b4b1e06d564e6d2ecb19de0daddbfbfa322a1b7545b5b1f8b418a2ecb46 0 20MB
Build cache usage: 0B
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
浠庝笂闈㈠彲浠ョ湅鍑烘潵浠栫粰鎴戜滑澶辫触鐨?docker锛屾垨鑰呰鍋滄鐨勫鍣ㄥ叏閮ㄩ兘娓呴櫎浜嗭紝閲婃斁浜嗗鍣ㄥ彲鍐欏眰鐨勫ぇ灏忥紝闀滃儚骞舵湭鍒犻櫎锛?/p>
娉ㄦ剰锛?/strong>
docker system prune 榛樿鍙細鍒犻櫎澶辫触鐨勬垨鑰呭仠姝㈢殑瀹瑰櫒锛屽拰浠栦滑鐨勫彲灞傦紝涔熶細鍒犻櫎鎮┖鐨勯暅鍍忥紝骞朵笉浼氭竻闄ゆ墍鏈夐暅鍍忋€?/p>
鎴戜滑鍙互浣跨敤 --filter 鍙傛暟娓呴櫎鍝竴绫诲鍣紝褰撳墠鏀寔鐨勫弬鏁?/p>
The currently supported filters are:
- until (
<timestamp>
) - only remove containers, images, and networks created before given timestamp- label (
label=<key>
,label=<key>=<value>
,label!=<key>
, orlabel!=<key>=<value>
) - only remove containers, images, networks, and volumes with (or without, in caselabel!=...
is used) the specified labels.
鎴戜滑鍙互浣跨敤-a 鍙傛暟娓呴櫎褰撳墠鏈哄櫒涓婃病鏈夎寮曠敤鐨勯暅鍍?/p>
# docker system prune -a
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot:20200714
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot@sha256:5a384898e7d11d99cefc55d9cd63518233b9751a5c4c465526cb14fff93985fd
deleted: sha256:3b4aa15b779d469887b8477b53d7cac5f4e8373ab39d0de015dec4c952ed8f87
deleted: sha256:6619936848bb2c35b219c1b2726c09fa6e8e54cb51449b6654ceeb45460236f7
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot:20200713
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot@sha256:f56d67fb69575ac79b48eb8f7a1f112966d01b6e80c1e89adaa454c8c686ca3d
deleted: sha256:1f7133d6f068499f91366eef403ed29478a9292720a3d59a8eb2f481560121aa
deleted: sha256:28044d3747ae44664b37ca14d99afe450f73e2ef05b960279f821b231a5cca6b
untagged: centos:test_volume
deleted: sha256:4c3708d6ffdd898ec25728870ad3c97bd27cbaaf9637b1b45a4e85e5a92095a9
deleted: sha256:a9d487236d0a89428a695de3a1c340c5e740bf213a35dcd9a8053025733531cc
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot:20200716
untagged: registry.cn-hangzhou.aliyuncs.com/smb/sellbot@sha256:b723f501cdebcee79b4d6b5b0859ce20718eded417928fa18d9f3b0135bc3ee4
deleted: sha256:f363f6d1f3f5fd25cedc0824fb33d17b5109d96a8a14a7931c7da8de812c37f6
deleted: sha256:16f95c955f85d8e1d5e6b3810e4843b9828bb0f5e215817661648b6d9c5a75b3
deleted: sha256:935e843cce2d562611a950de31beb63e17a9a1f3c3421ae3cab8db7f7ce3e1e0
deleted: sha256:bcf75aa1d1da5a81575b499af40a578888a8a7e0f813e0f516d7aefebc13690b
deleted: sha256:9ad3e1811704d30494e2d402d432c00d1d9153784a9b31cc058fffc672557606
deleted: sha256:a3473da06c6e367bb9ecb640ecac13d916568324a15ae7e8fed8f465e0690464
deleted: sha256:4a7021bd2ec6699a4c2a3c7df7ef9197b678ad56193b5b1d309a10d89532666d
deleted: sha256:6c3b476844a247d18c7eb535b9cc9d3d9f6d5063691cac5411f254b9fd7798f2
deleted: sha256:734e667e23a00543dbc5617963cb1473651316c0b1c0ba412e472960318d6e04
deleted: sha256:ffc9b21953f4cd7956cdf532a5db04ff0a2daa7475ad796f1bad58cfbaf77a07
untagged: centos:7.6.1810
untagged: centos@sha256:62d9e1c2daa91166139b51577fe4f4f6b4cc41a3a2c7fc36bd895e2a17a3e4e6
deleted: sha256:f1cb7c7d58b73eac859c395882eec49d50651244e342cd6c68a5c7809785f427
deleted: sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a
Total reclaimed space: 796.7MB
[root@zhangsf docker]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 1 1 1.224MB 0B (0%)
Containers 1 1 0B 0B
Local Volumes 1 0 20MB 20MB (100%)
Build Cache 0 0 0B 0B
浣嗘槸骞朵笉浼氭竻闄?VOLUME锛屽鏋滄垜浠兂娓呴櫎 VOLUME锛屽彲浠ヤ娇鐢ㄤ笅闈㈠弬鏁?浣嗘槸涓嶅缓璁娇鐢?/p>
# docker system prune -f --volumes
Deleted Volumes:
c72d1b4b1e06d564e6d2ecb19de0daddbfbfa322a1b7545b5b1f8b418a2ecb46
Total reclaimed space: 20MB
以上是关于Docker 鍨冨溇鍥炴敹鏈哄埗琛ュ厖的主要内容,如果未能解决你的问题,请参考以下文章
绗?3 娆¤ Effective Java锛岃繖 58 涓妧宸ф渶鍊硷紒