docker registry:2 删除镜像

以jenkins镜像为例

registry配置文件

# cat config.yml
version: 0.1
log:
 fields:
 service: registry
storage:
 delete:
  enabled: true
 cache:
  blobdescriptor: inmemory
 filesystem:
  rootdirectory: /var/lib/registry
http:
 addr: :5000
 headers:
  X-Content-Type-Options: [nosniff]
health:
 storagedriver:
 enabled: true
 interval: 10s
 threshold: 3

仓库启动脚本

#!/bin/bash
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v `pwd`/config.yml:/etc/docker/registry/config.yml \
-v /var/lib/registry:/var/lib/registry registry:2

查看镜像名

# curl -s -XGET localhost:5000/v2/_catalog | python -mjson.tool

查看镜像tag

# curl -s -XGET localhost:5000/v2/jenkins/tags/list|python -mjson.tool

查看镜像reversion

# ls /var/lib/registry/docker/registry/v2/repositories/jenkins/_manifests/revisions/sha256
0de43cde2c4b864a8e4a84bbd9958e47c5d851319f118203303d040b0a74f159

删除前

# docker exec -it 507320e9dbd3 sh
/ # cd /var/lib/registry/
/var/lib/registry # du -sch
704.9M  .
704.9M  total

删除镜像

curl -X DELETE localhost:5000/v2/jenkins/manifests/sha256:0de43cde2c4b864a8e4a84bbd9958e47c5d851319f118203303d040b0a74f159

垃圾回收

# docker exec -it 507320e9dbd3 \
registry garbage-collect /etc/docker/registry/config.yml

删除后

# docker exec -it 507320e9dbd3 sh
/ # registry garbage-collect /etc/docker/registry/config.yml
.
.
.
/ # du -sch
440.6M  .
440.6M  total

清除目录

此时执行curl还能查到jinkens镜像,进入容器删除如下目录:

/var/lib/registry/docker/registry/v2/repositories/jinkens

参考资料

https://www.jb51.net/article/111837.htm
https://www.jianshu.com/p/4053f6e5d8bf

你可能感兴趣的:(docker registry:2 删除镜像)