从私有注册表中删除标记的Docker镜像

如何从私有Docker注册表中的图像中删除错误添加的标记?选项-rmi似乎不适用于Docker 1.9.1中的远程映像.

user@ubuntu-user:~$docker --version  
Docker version 1.9.1, build a34a1d5

user@ubuntu-user:~$docker search myregistry:5000/user/image
NAME                                                                     
myregistry:5000/user/image:20160119                                         
myregistry:5000/user/image:20160119-20160120        

user@ubuntu-user:~$docker rmi myregistry:5000/user/image:20160119-20160120
Error response from daemon: could not find image: no such id: myregistry:5000/user/image:20160119-20160120
Error: failed to remove images: [myregistry:5000/user/image:20160119-20160120]
最佳答案
似乎没有简单的方法从今天的注册表中删除图像,看起来像注册表2.1 milestone的功能.

我们今天所拥有的选择之一就是不起作用

anovil@ubuntu-anovil remove-registry]$curl -X DELETE localhost:5000/v2/alpine/manifests/v1
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
[anovil@ubuntu-anovil remove-registry]$

是从注册表本身手动删除它.为了避免意外删除错误的文件,我用this script from github测试了它.我不保证这个脚本是如何工作的(虽然我在测试之前很快检查了它).

所以,我做了一个测试,这似乎工作:)

[1]我认为,您正在使用docker本身运行注册表.

[anovil@ubuntu-anovil remove-registry]$docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
88f8e1a1d7a7        registry:2          "/bin/registry /etc/d"   37 minutes ago      Up 37 minutes       0.0.0.0:5000->5000/tcp   registry
[anovil@ubuntu-anovil remove-registry]$

[2]我创建了一个只有FROM alpine内容的最小Dockerfile并创建了alpine:v1并推送到我在localhost:5000上运行的私有注册表.从注册表中查询它,它按预期返回.

[anovil@ubuntu-anovil remove-registry]$curl -X GET localhost:5000/v2/alpine/tags/list
{"name":"alpine","tags":["v1"]}
[anovil@ubuntu-anovil remove-registry]$

[3]然后我使用docker exec登录到注册表并检查磁盘使用情况,然后再进行实验

root@88f8e1a1d7a7:/# du -sch /var/lib/registry/                     
2.5M    /var/lib/registry/
2.5M    total
root@88f8e1a1d7a7:/# 

[4]在返回主机后,我将一个重文件(mongodb.tgz)复制到我的容器中,并创建了一个内置和推送的版本v2.

[anovil@ubuntu-anovil remove-registry]$docker build -t localhost:5000/alpine:v2 .
Sending build context to Docker daemon 61.99 MB
Step 1 : FROM alpine
 ---> 2314ad3eeb90
Step 2 : COPY mongodb.tgz /mongodb.tgz
 ---> d7c7645a3fe2
Successfully built d7c7645a3fe2
[anovil@ubuntu-anovil remove-registry]$docker push localhost:5000/alpine:v2
The push refers to a repository [localhost:5000/alpine] (len: 1)
d7c7645a3fe2: Pushed 
5ff05309724e: Image already exists 
v2: digest: sha256:7bea1ec2910170bd88412b622aee6129791673cf1fd8c0e1e34f15ec26428774 size: 4467
[anovil@ubuntu-anovil remove-registry]$

[5]在注册表中再次检查大小后,它已增加到62MB:

root@88f8e1a1d7a7:/# du -sch /var/lib/registry/                                                                               
62M /var/lib/registry/
62M total
root@88f8e1a1d7a7:/# 

[6]为了运行delete_docker_registry_image,您需要将脚本放入托管注册表的容器中,执行此操作的一个选项是使用curl.此外,此脚本需要jq.

root@88f8e1a1d7a7:/# apt-get update && apt-get install -y curl jq
...
root@88f8e1a1d7a7:/#

[7]运行脚本,首先尝试使用–dry-run选项,不要忘记版本标签(在本例中为v2),还有一个好的-h

root@88f8e1a1d7a7:/# delete_docker_registry_image --image alpine:v2 --dry-run
DRY_RUN: would have deleted tag directory: repositories/alpine/_manifests/tags/v2
DRY_RUN: would have deleted manifest revision: repositories/alpine/_manifests/revisions/sha256/7bea1ec2910170bd88412b622aee6129791673cf1fd8c0e1e34f15ec26428774
DRY_RUN: would have deleted directory: blobs/sha256/e2/e2cc9aed084e01fa5cf93c09121035ac4d712113425ae68b678c28591beec5c6
DRY_RUN: would have deleted directory: blobs/sha256/7a/7ada67971e952e353ab14d8f9bdd4e41e4c41099b05a5da09f2700b51d93908a
DRY_RUN: would have deleted directory: blobs/sha256/7b/7bea1ec2910170bd88412b622aee6129791673cf1fd8c0e1e34f15ec26428774
DRY_RUN: would have deleted layer metadata directory: repositories/alpine/_layers/sha256/e2cc9aed084e01fa5cf93c09121035ac4d712113425ae68b678c28591beec5c6
root@88f8e1a1d7a7:/# delete_docker_registry_image --image alpine:v2          
root@88f8e1a1d7a7:/#

[8]瞧!!

root@88f8e1a1d7a7:/# du -sch /var/lib/registry/                     
2.5M    /var/lib/registry/
2.5M    total
root@88f8e1a1d7a7:/#  

转载注明原文:从私有注册表中删除标记的Docker镜像 - 代码日志