Docker倉庫在2.1版本中支持了刪除鏡像的API,但這個刪除操作只會刪除鏡像元數據,不會刪除層數據。在2.4版本中對這一問題進行了解決,增加了一個垃圾回收命令,刪除未被引用的層數據。本文對這一特性進行了體驗,具體步驟如下。
1、部署鏡像倉庫
(1)啟動倉庫容器
這里需要說明一點,在啟動倉庫時,需在配置文件中的storage配置中增加delete=true配置項,允許刪除鏡像,本次試驗采用如下配置文件:
root@SZX1000041895:/# cat /home/config.ymlversion: 0.1log: fields: service: registrystorage: delete: enabled: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registryhttp: addr: :5000 headers: X-Content-Type-Options: [nosniff]health: storagedriver: enabled: true interval: 10s threshold: 3
(2)上傳鏡像
root@SZX1000041894:/home# docker tag centos 10.229.43.217:4000/xcb/centosroot@SZX1000041894:/home# docker push 10.229.43.217:4000/xcb/centosThepushrefersto a repository [10.229.43.217:4000/xcb/centos]5f70bf18a086: Pushed 4012bfb3d628: Pushedlatest: digest: sha256:5b367dbc03f141bb5246b0dff6d5fc9c83d8b8d363d0962f3b7d344340e458f6 size: 1331
(3)查看數據進行倉庫容器中,通過du命令查看大小,可以看到當前倉庫數據大小為61M。
root@SZX1000041895:~# docker exec -it test_registry /bin/bashroot@e6d36b0d7e86:/# du -sch /var/lib/registry61M .61M total
2、刪除鏡像
刪除鏡像對應的API如下:
DELETE /v2/<name>/manifests/<reference>
name:鏡像名稱
reference: 鏡像對應sha256值
(1)發送請求,刪除剛才上傳的鏡像
root@SZX1000041894:/home# curl -I -X DELETE http://10.229.43.217:4000/v2/xcb/centos/manifests/sha256:5b367dbc03f141bb5246b0dff6d5fc9c83d8b8d363d0962f3b7d344340e458f6HTTP/1.1 202 AcceptedDocker-Distribution-Api-Version: registry/2.0X-Content-Type-Options: nosniffDate: Wed, 06 Jul 2016 09:24:15 GMTContent-Length: 0Content-Type: text/plain; charset=utf-8
(2)查看數據大小
root@e6d36b0d7e86:/var/lib/registry# du -sch61M .61M total
可以看到數據大小沒有變化(只刪除了元數據)
3、垃圾回收
(1)進行容器執行垃圾回收命令
命令:
registry garbage-collect config.yml
root@e6d36b0d7e86:/var/lib/registry# registry garbage-collect /etc/docker/registry/config.ymlINFO[0000] Deletingblob: /docker/registry/v2/blobs/sha256/96/9687900012707ea43dea8f07a441893903dd642d60668d093c4d4d2c5bedd9eb go.version=go1.6.2 instance.id=4d875a6c-764d-4b2d-a7c2-4e85ec2b9d58INFO[0000] Deletingblob: /docker/registry/v2/blobs/sha256/a3/a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4 go.version=go1.6.2 instance.id=4d875a6c-764d-4b2d-a7c2-4e85ec2b9d58INFO[0000] Deletingblob: /docker/registry/v2/blobs/sha256/c3/c3bf6062f354b9af9db4481f24f488da418727673ea76c5162b864e1eea29a4e go.version=go1.6.2 instance.id=4d875a6c-764d-4b2d-a7c2-4e85ec2b9d58INFO[0000] Deletingblob: /docker/registry/v2/blobs/sha256/5b/5b367dbc03f141bb5246b0dff6d5fc9c83d8b8d363d0962f3b7d344340e458f6 go.version=go1.6.2 instance.id=4d875a6c-764d-4b2d-a7c2-4e85ec2b9d58
(2)查看數據大小
root@e6d36b0d7e86:/var/lib/registry# du -sch 108K .108K total
可以看到鏡像數據已被刪除,從61M變成了108K
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答
圖片精選