当前位置:首页 > 系统运维
删除本地 Registry 中的 docker 镜像
来源:靑龍一笑的博客  作者:靑龍一笑  发布时间:2021-04-13 13:42:15  点击量:687  评论:0

    默认是不允许删除本地 Registry 中的镜像。

1、查看镜像列表

[root@docker-registry ~]# curl http://docker-registry:5000/v2/_catalog
{"repositories":["centos"]}

2、查看 registry 容器 ID

[root@docker-registry ~]# docker ps -a
CONTAINER ID   IMAGE      COMMAND                  CREATED       STATUS          PORTS                    NAMES
f771472056b1   registry   "/entrypoint.sh /etc…"   7 hours ago   Up 14 minutes   0.0.0.0:5000->5000/tcp   confident_spence

3、查看配置文件

[root@docker-registry ~]# docker exec -it f771472056b1 cat /etc/docker/registry/config.yml
version: 0.1
log:
  fields:
    service: registry
storage:
  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

4、修改配置文件    

[root@docker-registry ~]# docker exec -it f771472056b1 vi /etc/docker/registry/config.yml

    增加 delete 段,将 enabled 设置为 true,内容如下:

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

5、重启容器,使配置生效

[root@docker-registry ~]# docker restart f771472056b1

6、获取镜像的摘要信息

[root@docker-registry ~]# curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://docker-registry:5000/v2/centos/manifests/7
HTTP/1.1 200 OK
Content-Length: 529
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e"
X-Content-Type-Options: nosniff
Date: Sat, 10 Apr 2021 14:29:04 GMT

7、删除镜像

[root@docker-registry ~]# curl -I -X DELETE http://docker-registry:5000/v2/centos/manifests/sha256:e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e
HTTP/1.1 202 Accepted
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Sat, 10 Apr 2021 14:34:34 GMT
Content-Length: 0

8、验证镜像是否被删除

(1)方法一

[root@docker-registry ~]# curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://docker-registry:5000/v2/centos/manifests/7
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Sat, 10 Apr 2021 14:36:30 GMT
Content-Length: 91

(2)方法二

[root@docker-client ~]# docker pull docker-registry:5000/centos:7
Error response from daemon: manifest for docker-registry:5000/centos:7 not found: manifest unknown: manifest unknown
版权所有 © 2005-2023 靑龍一笑的博客  Powered by C.S.Ricen
Copyright © 2005-2023 by www.ricensoftwares.com.cn  All Rights Reserved.

欢迎光临本站,这里是靑龍一笑的博客。

因资金匮乏,本站已迁到国外的免费空间,可能导致本站的访问速度较慢,由此给您带来的不便,敬请谅解。

您可以通过下方的“支持本站建设”链接,给本站提供资金支持。

Free Web Hosting