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>, or label!=<key>=<value>) - only remove containers, images, networks, and volumes with (or without, in case label!=... 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 鍨冨溇鍥炴敹鏈哄埗琛ュ厖的主要内容,如果未能解决你的问题,请参考以下文章

[绉戞櫘]ES6涓€浜涗笉甯歌鐨勫皬鐭ヨ瘑

鏈哄櫒瀛︿範锛?3-鍨冨溇閭欢鍒嗙被2

绗?3 娆¤ Effective Java锛岃繖 58 涓妧宸ф渶鍊硷紒

鍞犱竴鍞犺瀺浜戠殑娑堟伅琛ュ伩鏈哄埗

Java鍘嗗彶[鍙蹭笂鏈€璇︾粏鐨勯槓杩颁簡Java鍙戝睍鐨勫巻鍙茶繃绋媇

鍨冨溇浠g爜涔﹀啓鍑嗗垯锛堟湁鎰忔€濓級