remove docker repository on remote docker registry

JamesThomasMoon picture JamesThomasMoon · Apr 27, 2017 · Viewed 10.4k times · Source

Given a docker registry managing multiple docker repositories, how do I delete one of the repositores?

In my case,

$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo1", "repo2", "repo3"]}

I want to remove repository repo1 so that _catalog looks like

$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo2", "repo3"]}

We can see repo1 appears to have only the default "latest" image tag.

$ curl -X GET localhost:5000/v2/repo1/tags/list
{"name":"repo1","tags":["latest"]}

(Maybe that affects being able to delete repo1?)



I have tried...

The following commands returned 404 page not found:

$ curl -X DELETE localhost:5000/v1/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repo1

And the following returned {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

$ curl -X DELETE localhost:5000/v2/repo1/manifests/latest

Using

The docker-registry is registry/2.0

curl -vX GET localhost:5000/v2/
< HTTP/1.1 200 OK
...
< Docker-Distribution-Api-Version: registry/2.0
...

and

$ /bin/registry github.com/docker/distribution v2.4.1

Answer

Negar Zamiri picture Negar Zamiri · Jan 8, 2020

by enabling DELETE API you're only able to delete the TAG not the whole repository from v2/_catalog.

in order to do this, you should:


1. enable DELETE API:

1.1 by config.yml : storage.delete.enabled:true

1.2 by env: -e REGISTRY_STORAGE_DELETE_ENABLED=true

2. get the tag reference via GET /v2/<name>/manifests/<tag> (don't forget to have Header Accept: application/vnd.docker.distribution.manifest.v2+json).

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

3. send DELETE /v2/<name>/manifests/<sha256:xxx>

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

5. remove files: rm -r /var/lib/registry/docker/registry/v2/repositories/<name>/<tag>


finally: now you can see

curl -X GET localhost:5000/v2/_catalog {"repositories":["repo2", "repo3"]}



ps.

consequences of 5: https://github.com/docker/distribution/issues/2983#issuecomment-530251232