怎样删除自建的docker-registry中的image?


我所搭建的docker-registry直接运行在ubuntu上,并非运行在container中。docker-registry的地址为: 136.187.82.15:5000

我采用以下命令删除repository
curl -X DELETE http://136.187.82.15:5000/v1/repositories/library/ubuntu/

然后再在到储存镜像的目录(/var/docker-registry)里面查看
find .
输出结果:(可知ubuntu的repository已经删除了,但是image还在!)
./docker-registry.db
./registry
./registry/images
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/layer
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/json
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/_checksum
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/ancestry
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/layer
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/json
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/_checksum
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/ancestry
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/layer
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/json
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/_checksum
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/ancestry
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/_checksum
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/ancestry
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/layer
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/json
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/_checksum
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/ancestry
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/layer
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/json
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/_checksum
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/ancestry
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/layer
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/json
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/_checksum
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/ancestry
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/layer
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/json
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/_checksum
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/ancestry
./registry/repositories
./registry/repositories/library
./registry/repositories/library/busybox
./registry/repositories/library/busybox/_index_images
./registry/repositories/library/busybox/tagtest_json
./registry/repositories/library/busybox/tag_test

当我再次push ubuntu到docker-registry中时
sudo docker push 136.187.82.15:5000/ubuntu:14.04

输出结果:(“already pushed, skipping"表明image确实没删掉)
The push refers to a repository [136.187.82.15:5000/ubuntu] (len: 1)
Sending image list
Pushing repository 136.187.82.15:5000/ubuntu (1 tags)
Image 511136ea3c5a already pushed, skipping
Image 53f858aaaf03 already pushed, skipping
Image 837339b91538 already pushed, skipping
Image 615c102e2290 already pushed, skipping
Image b39b81afc8ca already pushed, skipping
Pushing tag for rev [b39b81afc8ca] on {http://136.187.82.15:5000/v1/repositories/ubuntu/tags/14.04}

再次到储存镜像的目录(/var/docker-registry)里面查看
find .
输出信息: (此时ubuntu镜像的repository又恢复了)
./docker-registry.db
./registry
./registry/images
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/layer
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/json
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/_checksum
./registry/images/ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2/ancestry
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/layer
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/json
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/_checksum
./registry/images/837339b915388417a842c87a681a5448df2509068c8d3efd1638f1fad2eacea2/ancestry
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/layer
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/json
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/_checksum
./registry/images/b39b81afc8cae27d6fc7ea89584bad5e0ba792127597d02425eaee9f3aaaa462/ancestry
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/_checksum
./registry/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/ancestry
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/layer
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/json
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/_checksum
./registry/images/df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b/ancestry
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/layer
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/json
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/_checksum
./registry/images/53f858aaaf03033e088d357df23e311d71aa93ac578ef39aa8230580ea95076f/ancestry
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/layer
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/json
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/_checksum
./registry/images/4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125/ancestry
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/layer
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/json
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/_checksum
./registry/images/615c102e2290b70d38d89c03a1ad263da8bd8b05fb7fc8479174e5fd2215520e/ancestry
./registry/repositories
./registry/repositories/library
./registry/repositories/library/ubuntu
./registry/repositories/library/ubuntu/tag14.04_json
./registry/repositories/library/ubuntu/_index_images
./registry/repositories/library/ubuntu/tag_14.04
./registry/repositories/library/busybox
./registry/repositories/library/busybox/_index_images
./registry/repositories/library/busybox/tagtest_json
./registry/repositories/library/busybox/tag_test

Docker Registry API只有删除tag和repository的API, 是否无法删除docker-registry中的image,只能直接删除目录,重新配置docker-registry?
已邀请:

田浩浩 - wizmacau developer

赞同来自: KiwenLau


指定一个tag试试
curl -X DELETE http://136.187.82.15:5000/v1/repositories/library/ubuntu/tags/14.04 HTTP/1.1

DockOne - DockOne官方账号

赞同来自: KiwenLau


目前官方还不支持,继续等吧。

zhengxiaochuan - 京东-云平台南京研发中心-JDOS团队

赞同来自:

analyser

赞同来自:


有用的话,建议直接贡献到 docker github

dxwker - Docker是当前非常热的云计算技术,Docker将APP变成标准化的、可移植的、自管理的组件,在任何主流系统中开发、调试和运行,相比传统的虚拟主机更加灵活,速度更快。另外我是才云Docker工程师,欢迎有问题一起交流!

赞同来自:


是可以删除的,但是索引需要像我之前一样的手动删除
curl -X DELETE /v2/<name>/manifests/<reference>
//需求注意的是<reference>不能是标记,一定要是digset,此值可以通过pull或push时查看到,但不知道有没有其他快捷方法查看,欢迎知道的告知一下。
curl -X DELETE https://markthink:123456a@registry.51yixiao.com/v2/centos/manifests/sha256:a667716cc9ad8547db5915ba5190d2d7748161065726b13e86840e3b85a572b3

ppcelery - 直立猿

赞同来自:


有接口可以获取到 digest


HEAD /v2/<name>/manifests/<reference>
其中 name 是 repo/imagename,reference 是 tagname

houht - 云计算,大数据方向研发

赞同来自:

dotNetDR_

赞同来自:


registry的启动程序有2参数,你自己看看。一个是启服务,一个是清理image

todaygood

赞同来自:


我发现不行啊,请高手指点.

[root@server120 v2]# curl http://localhost:5000/v2/_catalog
{"repositories":["hello-world"]}
[root@server120 v2]# curl http://localhost:5000/v2/hello ... atest
{
"schemaVersion": 1,
"name": "hello-world",
"tag": "latest",
"architecture": "amd64",
"fsLayers": [
{
"blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
},
{
"blobSum": "sha256:b04784fba78d739b526e27edc02a5a8cd07b1052e9283f5fc155828f4b614c28"
}
],
"history": [
{
"v1Compatibility": "{\"architecture\":\"amd64\",\"config\":{\"Hostname\":\"adc90845fac3\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":[\"/hello\"],\"ArgsEscaped\":true,\"Image\":\"sha256:6e47ed59f6b5dbe00587d2a08e6972feaf9d10eee5a2b107099b4707e934c0c7\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":{}},\"container\":\"daea997c17c2861b425edaa87aa7556b4b2d1d4913d2b66014696f2ce340306b\",\"container_config\":{\"Hostname\":\"adc90845fac3\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) \",\"CMD [\\"/hello\\"]\"],\"ArgsEscaped\":true,\"Image\":\"sha256:6e47ed59f6b5dbe00587d2a08e6972feaf9d10eee5a2b107099b4707e934c0c7\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":{}},\"created\":\"2017-06-14T19:29:01.037740325Z\",\"docker_version\":\"17.03.1-ce\",\"id\":\"f054dc87ed76d853247ffefeaeac52ccbb07d1444949ca324d04365b29c94323\",\"os\":\"linux\",\"parent\":\"fc882b159a63d6da4646a4c54194c32fad6c9b682655993c5c39ac021c0fd367\",\"throwaway\":true}"
},
{
"v1Compatibility": "{\"id\":\"fc882b159a63d6da4646a4c54194c32fad6c9b682655993c5c39ac021c0fd367\",\"created\":\"2017-06-14T19:28:14.683824199Z\",\"container_config\":{\"Cmd\":[\"/bin/sh -c #(nop) COPY file:b65349dad8105cbef74456e9c0c9da5d001e9eb2ade4b3c21e107909aee5b25a in / \"]}}"
}
],
"signatures": [
{
"header": {
"jwk": {
"crv": "P-256",
"kid": "TOTH:O25Z:HJGM:6ZVI:HTGG:BXG3:BNPS:PT44:B25G:ZDII:T6M5:6OP6",
"kty": "EC",
"x": "2ebyt7cxp8XRGLwe3q1UwRk6DupW2oqqagzwTszjagg",
"y": "v1IXx0vKD7AtEDgxivTGHWtE990br9_ajNmlm24Z0Fg"
},
"alg": "ES256"
},
"signature": "8DwsoI7VyzQ-U2PWa4rsA1bBZoshhXyFBHvCxv6uSu6CRK3dw5Bkc4YN-fF796vZigi5TIaPMvmiP4ULnf_dxQ",
"protected": "eyJmb3JtYXRMZW5ndGgiOjIxNDcsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxNy0wNy0xMFQwODozMToxN1oifQ"
}
]
}

[root@server120 v2]# curl -X DELETE http://localhost:5000/v2/hello ... atest
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

[root@server120 kolla]# docker pull localhost:5000/hello-world:latest
Trying to pull repository localhost:5000/hello-world ...
latest: Pulling from localhost:5000/hello-world
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
[root@server120 kolla]# curl -X DELETE http://localhost:5000/v2/hello ... ff74f
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

anlenshen

赞同来自:


curl -X delete 成功的标志是“HTTP/1.1 202 Accepted"
之后去registry实际目录去清理文件
/var/lib/registry # du -sch
35.2M .
35.2M total
执行命令
registry garbage-collect /etc/docker/registry/config.yml
执行成功标志是: blob eligible for deletion
之后再执行du -sch就会有惊喜

要回复问题请先登录注册