I would like to delete particular or all manifests in my private docker registry remotely (v2 api) to make it possible images data to be collected by gc. I found this tool, but it only works with tags. I decided to extend it. I would like to enumerate manifests. Is it possible to get manifests list? I can't find something useful on this.
I checked those and I'm also searching the web, but with no success.
- https://docs.docker.com/registry/spec/api/
- https://docs.docker.com/registry/garbage-collection/
--UPDATE--
Either of both results in 404 error of course (I just prefer using wget
). For
https://<registry-origin>/v2/gk-backend/tags/list
I got {"name":"gk-backend","tags":["latest"]}
as I expect. When I try father to get the manifest I have 404. I issue the request by using wget
like
wget --method=HEAD --header="Accept: application/vnd.docker.distribution.manifest.v2+json" --no-check-certificate --http-user user --http-password pass https://<registry-origin>/v2/wjs-wealth/manifests/gk-backend:latest -O-
And curl
also gives me 404
curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -sI --user user:pass https://<registry-origin>/v2/wjs-wealth/manifests/gk-backend:latest
I have the same problem. If the a docker image (called manifest) pushed to Docker registry v2.0 with same tag, new manifest will take the tag and the old one will NOT deleted instead of existed with no tag assigned.
Such old manifests cannot list from REST API without knowning their digests, and garbage collection will not delete them.
One way I found to get list of manifests of a docker registry repository is via garbage collection tool. Run docker exec -it registry registry garbage-collect --dry-run /etc/docker/registry/config.yml
. This command will print all manifests (including those assigned tag) of all repositories. Such as:
hello-world
hello-world: marking manifest sha256:fea8895f450959fa676bcc1df0611ea93823a735a01205fd8622846041d0c7cf
hello-world: marking blob sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb
hello-world: marking blob sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
hello-world: marking configuration sha256:690ed74de00f99a7d00a98a5ad855ac4febd66412be132438f9b8dbd300a937d
ubuntu
4 blobs marked, 0 blobs eligible for deletion
With grep tool, it is easy to filter out manifest information only.
Then you can call delete REST API to delete unused manifests. Take attention not to delete those manifest with tag assigned.
DELETE REST API only remove manifest information, image data in blob will not delete, so run garbage collection command again without --dry-run
to remove unused blob: docker exec -it registry registry garbage-collect /etc/docker/registry/config.yml
You need to run this command to get a list of your tags
curl https://<registry>/v2/<repoName>/tags/list
Now we want the manifest for each tag - because we don't want to delete it as per comphilip's answer.
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -sI "https://<registry>/v2/<repoName>/manifests/<tag>" | grep "Docker-Content-Digest" | sed 's/Docker-Content-Digest: //;s/\r$//'
It is very important to include the header otherwise you get a different Docker-Content-Digest.
This will give you a list of manifests you need to exclude.
Alternatively you can use this method: docker registry cleanup