操作步骤
- 通过环境变量修改默认配置,允许删除
- 获取image的sha值
- 进入registry容器中,执行垃圾回收
- 删除残留目录
#环境变量 REGISTRY_STORAGE_DELETE_ENABLED=true 用于覆盖默认设置
docker run -d -v /opt/registry:/var/lib/registry -e REGISTRY_STORAGE_DELETE_ENABLED=true -p 5000:5000 --restart=always --name registry registry:2
#声明要删除的镜像名称
image=...
#获取sha
sha=`ls /opt/registry/docker/registry/v2/repositories/$image/_manifests/revisions/sha256`
#删除 需替换registryurl
curl -XDELETE http://<registryurl>/v2/$image/manifests/sha256:$sha
#垃圾回收
docker exec -it registry sh
registry garbage-collect /etc/docker/registry/config.yml
exit
#删除残留目录
rm -rf /opt/registry/docker/registry/v2/repositories/$image
参考:
https://docs.docker.com/registry/configuration/#delete
https://docs.docker.com/registry/garbage-collection/
https://blog.csdn.net/happyzwh/article/details/86300733
https://www.jianshu.com/p/2d63b0461a51