Table of Contents
Clean up docker registry
After docker containers are backed up daily to docker registry, clean up process is required.
Note: If the image without tag, and if it can be found client locately, then can run command docker inspect
to find out. Otherwise, can check "Run command from server" section find out.
List _catalog
(repositries)
Following curl command can be used to display all _catalog
(repositries).
curl https://username:password@registry.example.net/v2/_catalog
List images (tags) for each repositry
Following curl command can be used to display tags for specific repo
curl https://username:password@registry.example.net/v2/${repo}/tags/list
Get Digest
Using pull request
Use pull image command to get digest as below.
docker pull registry.example.net/${repo}:20210624
20210624: Pulling from user/host/dnsmasq
...
22b5d63ad977: Already exists
8e2e66517d7e: Pull complete
Digest: sha256:7535af1f65524f9200b901fc31b9c779819e45c0502ef99605666842a319908f
Get digest when deleting local image
Using delete local image action also can get digest as well
docker rmi registry.example.net/${repo}:20210619
# Untagged: registry.example.net/user/host/dnsmasq:20210619
# Untagged: registry.example.net/user/host/dnsmasq@sha256:e300ff463dc18c7b3bf3964dc5a9832f613d829285a0da49e5fd37519dc7d0fc
# Deleted: sha256:35baba3d5948b5844b67adcd6a236905039e929f8647d4e4afc9e64e9460d557
# Deleted: sha256:bd681f3956f55dc028bae7ca4c2657457824a0e356c59705302fb084660a669b
The Digest is the second tag.
Note: The first deleted sha256 allowed to be deleted too, but not the second deleted. Don't understand why
Run command from client
Run following command to get Digest
curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET https://username:password@registry.example.net/v2/${repo}/manifests/20210624 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'
Run command from server
This is usefull if there is no image at client and no tag for specfic image.
docker exec privateregistry_registry_1 bin/registry garbage-collect --dry-run /etc/docker/registry/config.yml | grep '${repo}: marking manifest' | awk '{print $4}'
Check manifests exists or not
curl https://username:password@registry.example.net/v2/${repo}/manifests/sha256:xxxxxxxxxxxxxxxx
Delete tag
curl -X DELETE https://username:password@registry.example.net/v2/${repo}/manifests/sha256:xxxxxxxxxxxxxxxx
Delete _catalog
The v2 registry doesn't allow deleting only certain tags from an image, and deletion of tags is in an open PR for a future version of the Registry (https://github.com/docker/distribution/pull/2169).
rm -rf docker/registry/v2/repositories/${repo}/
*Note: After delete, garbage-collect, restart, the repo is still reporting out as empty _catalog
.
Run garbage-collect
Login to registry server and run following command
docker exec registry bin/registry garbage-collect --delete-untagged /etc/docker/registry/config.yml
If the repo is still listed in the output, need to delete them too.
Restart registry if necessary
docker restart registry
References
Docker Private Registry - Deleted all images, but still showing in catalog
Clean Up Your Docker Registry
Delete repository from v2 private registry
Pull Request - New Tags API #2169
Docker Registry HTTP API V2