CentOS 7搭建Docker私有库及删除库内镜像(2)

curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I -XGET :5000/v2/busybox/manifests/latest
HTTP/1.1 200 OK
Content-Length: 527
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649"
X-Content-Type-Options: nosniff
Date: Fri, 19 Jul 2019 06:09:44 GMT

删除私有库镜像

curl -I -XDELETE :5000/v2/busybox/manifests/sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
HTTP/1.1 202 Accepted
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Fri, 19 Jul 2019 06:10:56 GMT
Content-Length: 0

查看镜像信息可以看到镜像的标签显示为空 null

curl :5000/v2/busybox/tags/list
{"name":"busybox","tags":null}

这里虽然删除了,但是实际上硬盘地址还没有释放,是因为docker删除p_w_picpath只是删除的p_w_picpath的元数据信息。层数据并没有删除。现在进入registry中进行垃圾回收。

进入registry容器

docker exec -it 071105c54db3 /bin/sh
/ # cd /var/lib/registry/

查看镜像大小

/var/lib/registry # du -sch
756.0K .
756.0K total

执行回收命令

/var/lib/registry # registry garbage-collect /etc/docker/registry/config.yml
busybox

0 blobs marked, 3 blobs and 0 manifests eligible for deletion
blob eligible for deletion: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/89/895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 go.version=go1.11.2 instance.id=7c37e39d-6ad1-4139-b9d1-592a900b0902 service=registry
blob eligible for deletion: sha256:db8ee88ad75f6bdc74663f4992a185e2722fa29573abcc1a19186cc5ec09dceb
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/db/db8ee88ad75f6bdc74663f4992a185e2722fa29573abcc1a19186cc5ec09dceb go.version=go1.11.2 instance.id=7c37e39d-6ad1-4139-b9d1-592a900b0902 service=registry
blob eligible for deletion: sha256:ee153a04d6837058642958836062f20badf39f558be3e6c7c7773ef7d8301d90
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/ee/ee153a04d6837058642958836062f20badf39f558be3e6c7c7773ef7d8301d90 go.version=go1.11.2 instance.id=7c37e39d-6ad1-4139-b9d1-592a900b0902 service=registry

再次查询,发现回收资源执行成功

/var/lib/registry # du -sch
0 .
0 total

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e298eadc4d889cced463b460d8b34142.html