docker registry 删除镜像
1.背景
node1,node2:
CentOS Linux release 7.6.1810 (Core)
2.准备工作
# 1.安装
docker run --name registry -d -p 5000:5000 -v /myregistry/:/var/lib/registry registry:2
# 2.修改/etc/docker/daemon.json (node1,node2都修改)
{
"registry-mirrors": ["https://w6pljua0.mirror.aliyuncs.com"],
"insecure-registries":["10.20.9.36:5000"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
# 3.进入容器修改config.yml
storage:
delete:
enabled: true
# 4.重启docker和容器 (node2只需要重启docker)
systemctl daemon-reload
systemctl restart docker.service
docker restart 1621fffebe88 (registry的容器ID)
# 5.准备镜像
[root@node01 work]# curl -X GET http://10.20.9.36:5000/v2/hello-word/tags/list
{"name":"hello-word","tags":["v1","v2"]}
3. 获取镜像Digest
# 获取镜像push成功后生成的 digest:sha256值
[root@node01 work]# curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -XGET 10.20.9.36:5000/v2/hello-word/manifests/v1
HTTP/1.1 200 OK
Content-Length: 525
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 (此值即/index)
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042"
X-Content-Type-Options: nosniff
Date: Mon, 04 Jan 2021 08:56:31 GMT
3. 删除镜像
3.1 通过删除Docker-Content-Digest删除镜像
# 1.获取镜像tag list
[root@node02 ~]# curl -X GET http://10.20.9.36:5000/v2/hello-word/tags/list
{"name":"hello-word","tags":["v1","v2"]}
# 2.获取镜像Docker-Content-Digest
[root@node02 ~]# curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -XGET 10.20.9.36:5000/v2/hello-word/manifests/v2
HTTP/1.1 200 OK
Content-Length: 946
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:e751ec8e3d5e68f77f59a6b7fdc612704840ef3a7a3be28febd51625161051c5
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:e751ec8e3d5e68f77f59a6b7fdc612704840ef3a7a3be28febd51625161051c5"
X-Content-Type-Options: nosniff
Date: Mon, 04 Jan 2021 09:08:14 GMT
# 3.查看node1空间大小
[root@node01 work]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda2 99G 40G 60G 40% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 82M 1.8G 5% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/vda1 1014M 137M 878M 14% /boot
# 4.删除镜像
[root@node02 ~]# curl -X DELETE http://10.20.9.36:5000/v2/hello-word/manifests/sha256:e751ec8e3d5e68f77f59a6b7fdc612704840ef3a7a3be28febd51625161051c5
# 5.获取镜像tag list
[root@node02 ~]# curl -X GET http://10.20.9.36:5000/v2/hello-word/tags/list
{"name":"hello-word","tags":["v1"]}
# 6.查看node1空间大小 (空间未变化)
[root@node01 work]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda2 99G 40G 60G 40% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 82M 1.8G 5% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/vda1 1

本文介绍了如何在Docker Registry中删除镜像,包括获取镜像Digest、通过Docker-Content-Digest删除镜像及其存在的问题,以及直接删除blob和blobs的方法。
最低0.47元/天 解锁文章
8890

被折叠的 条评论
为什么被折叠?



