remove registry

https://stackoverflow.com/questions/43666910/remove-docker-repository-on-remote-docker-registry

  1. enable DELETE API:

    1. by config.yml : storage.delete.enabled:true
    2. by env: -e REGISTRY_STORAGE_DELETE_ENABLED=true
  2. get the tag reference via GET /v2//manifests/ (don't forget to have Header Accept: application/vnd.docker.distribution.manifest.v2+json).

in response headers, you have docker-content-digest: sha256:xxx

  1. send DELETE /v2//manifests/sha256:xxx

  2. run garbage collector: bin/registry garbage-collect /etc/docker/registry/config.yml

  3. remove files: rm -r /var/lib/registry/docker/registry/v2/repositories//

registry api


DELETE /v2/<name>/manifests/<reference>

/v2/python/manifests/

/v2/quay.io/coreos/flannel/manifests/

https://docker-hub.one-k.xyz/v2/quay.io/coreos/flannel/tags/list


https://docker-hub.one-k.xyz/v2/openstack.kolla/ubuntu-source-mariadb-clustercheck/manifests/wallaby

https://docker-hub.one-k.xyz/v2/openstack.kolla/ubuntu-source-mariadb-clustercheck/manifests/sha256:d9992cc4f3edd222c9871dac91fbdd3cb4cf47570f0038e4574781df77808eed


c0cd30b832e6

registry api


GET	/v2/<name>/tags/list	Tags	Fetch the tags under the repository identified by name.
GET	/v2/<name>/manifests/<reference>	Manifest	Fetch the manifest identified by name and reference where reference can be a tag or digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.

和 我们 free_cicd 业务 场景 也没啥 任何 冲突, 这边 主要 针对 gpu 企业 生产, 单子 都是 100w 以上的, 我们 搞好 之后 想 卖 10w 以下的 普通办公 还有 家庭 共享高档 pc

test delete by http

Deleting an Image
An image may be deleted from the registry via its name and reference. A delete may be issued with the following request format:

DELETE /v2//manifests/
For deletes, reference must be a digest or the delete will fail. If the image exists and has been successfully deleted, the following response will be issued:

202 Accepted
Content-Length: None
If the image had already been deleted or did not exist, a 404 Not Found response will be issued instead.

Note When deleting a manifest from a registry version 2.3 or later, the following header must be used when HEAD or GET-ing the manifest to obtain the correct digest to delete:

简单讲 就是 version 2.3 or later,
必须 根据 digest 才可以 删除 image




curl -H "Content-Type: application/json" -X GET   https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/victoria

curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json" --head  https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/victoria


curl  -X DELETE  https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/sha256:669b590a6a5c31176cd8922d25b78e53875ffa3782f99e1b42b90872c21705da
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

# 删除前
du -shm  ./*
57912   ./docker

curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json"  -X DELETE  https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/sha256:6fca60ed944301fd97a45ce4b706cddff1f5948d1be56dcc25fe3406169cfed9

curl -I -X DELETE  https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/669b590a6a5c31176cd8922d25b78e53875ffa3782f99e1b42b90872c21705da


# 回收 registry 空间
#   --delete-untagged=true  必须 加, 否则 registry 很多 空间 都不 释放.
docker exec -it registryssl_register-ssl_1  bin/registry garbage-collect   /etc/docker/registry/config.yml 


# 删除 成功
https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/tags/list
# {
# name: "kolla/ubuntu-binary-chrony",
# tags: null
# }


https://docker-hub.one-k.xyz/v2/kolla/ubuntu-binary-chrony/manifests/victoria
# {
# name: "kolla/ubuntu-binary-chrony",
# tags: [
# "victoria"
# ]
# }

批量 删除 脚本


curl https://docker-hub.one-k.xyz/v2/_catalog?n=1000 2>&1  |  jq  '.repositories'

apt install jq -y


echo `curl https://docker-hub.one-k.xyz/v2/_catalog?n=1000 2>1` | jq '.repositories'  | grep -oE '[a-z0-9./-]+'  | grep -i 'kolla/ubuntu-binary'
kolla/ubuntu-binary-chrony
kolla/ubuntu-binary-cinder-api
...


tag_name='wallaby'
repositories_name='quay.io/openstack.kolla'

function del_registry_img(){
    img_name=${1}

    ref_sha=$(curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json" --head  https://docker-hub.one-k.xyz/v2/${img_name}/manifests/${tag_name} 2>1 | grep -i 'docker-content-digest'  | grep -oE '[a-z0-9:]{20,}' )

    curl  --header "Accept: application/vnd.docker.distribution.manifest.v2+json"  -X DELETE  https://docker-hub.one-k.xyz/v2/${img_name}/manifests/${ref_sha}
}

for img_name in $( echo `curl https://docker-hub.one-k.xyz/v2/_catalog?n=1000 2>1` | jq '.repositories'  | grep -oE '[a-z0-9./-]+'  | grep -i ${repositories_name} )
do
    del_registry_img  ${img_name}  &
done


# 回收垃圾前
du -shm  ./*
56284   ./docker

# 回收 registry 空间
#   --delete-untagged=true  必须 加, 否则 registry 很多 空间 都不 释放.
docker exec -it registryssl_register-ssl_1  bin/registry garbage-collect   /etc/docker/registry/config.yml --delete-untagged
du -shm  /free_cicdfs0/k8s_data/registry_ssl/registry/docker/*
53531   ./docker



rm -rf /free_cicdfs0/k8s_data/registry_ssl/registry/docker/registry/v2/repositories/quay.io/

# 定位 大文件
du -sh ./*
2.0K    ./0e77cd93e858cf8b1bc1640c470f3e4ca53f69f25327c16f05b43139e532aa7b
129K    ./0eb1c8b8e410da40903631c89f617970663274212b863e194a676ea927368cd2
18G     ./0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579

docker exec -it registryssl_register-ssl_1  bin/registry garbage-collect   /etc/docker/registry/config.yml --delete-untagged  | grep -i 0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579
ceph/ceph-dev: marking blob sha256:0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579


du -d 3 -h ./* | sort -sh  | tail
487M    ./ec
502M    ./ca
1.1G    ./38/3853fdf1e4493f023b9cf5b40e2f825ce112771fb29639c16bf6839d9bdf1fd4
1.1G    ./38
1.3G    ./5a/5a16766e855c48ae4e8b8e459ca95ab6adbc62ca7c66d2bac6e73947fe153cbb
1.3G    ./5a
16G     ./8c/8c435ab66a267e54b6349bcfd8ca7259bff7735e1ac8c8abc06c11617e11ef2a
16G     ./8c
18G     ./0e/0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579
18G     ./0e

docker exec -it registryssl_register-ssl_1  bin/registry garbage-collect   /etc/docker/registry/config.yml --delete-untagged  | grep -iE '8c435ab66a267e54b6349bcfd8ca7259bff7735e1ac8c8abc06c11617e11ef2a|0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579'
ceph/ceph-build: marking blob sha256:8c435ab66a267e54b6349bcfd8ca7259bff7735e1ac8c8abc06c11617e11ef2a
ceph/ceph-dev: marking blob sha256:0ed82ff9ed21be65a3aebc52ed2e19558bb778d5bdd8035fdcd383375901f579

linux 查找命令

linux 使用ctrl+r进行搜索输入过的命令


https://docker-hub.one-k.xyz/v2/_catalog?n=1000

https://docker-hub.one-k.xyz/v2/quay.io/openstack.kolla/ubuntu-source-cinder-api/tags/list


docker registry  clean repositories


欢迎大家一起交流呀
qq群:3638803451
vx:wxid_sgdelhiwombj12