从私有registry中删除标记的Docker镜像

如何从私人Dockerregistry中的图像中删除错误添加的标签? 选项-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] 

从今天起,似乎没有简单的方法从registry中删除图像,并且看起来像是registry2.1里程碑的一个function。

其中一个选项,我们今天有没有这个工作

 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]$ 

是从registry本身手动删除它。 只是为了避免意外删除错误的文件,我用github中的这个脚本testing了它。 我不能保证这个脚本是如何工作的(尽pipe在testing之前我很快就检查过了)。

所以,我做了一个testing,似乎工作:)

[1]我认为,你正在运行与docker本身的registry。

 [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]我创build了一个只有FROM alpine内容的最小Dockerfile,并创build了alpine:v1,并推送到在localhost:5000上运行的私有registry。 从registry中查询,它按预期返回。

 [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 execlogin到registry,在做实验前检查磁盘的使用情况

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

[4]回到我的主机后,我复制了一个沉重的文件(mongodb.tgz)到我的容器中,并创build了一个内置的推送版本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]在registry中再次检查大小后,它增加到了62MB:

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

[6]为了运行delete_docker_registry_image ,您需要将脚本放入托piperegistry的容器中,一个选项是使用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:/# 

我不确定这是否有帮助。 但请看看我的build议在这里(评论来自mphanikumars)

https://github.com/docker/docker-registry/issues/988