burnettk / delete-docker-registry-image

If you are running a private v2 docker registry, and you are storing your data on disk, running this script from the machine where the data lives will let you fully delete an image or tag

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Max retries exceeded with url: /v2/_catalog (Caused by <class 'socket.error'>: [Errno 111] Connection refused)

lvthillo opened this issue · comments

Hi,
I'm using Docker Version: 1.11.2.
I'm using the two scripts you offer. The first one (delete_docker_registry_image) works fine. After doing the export I'm able to delete repo's.
But when I try to execute the second script (clean_old_versions) it does not work.

I've my registry (secured with a selfsigned cert) and I pushed:

myreg.com/busybox/busy:1
myreg.com/busybox/busy:2
myreg.com/busybox/busy:3
myreg.com/busybox/busy:4
myreg.com/busybox/busy:latest

Now I try to delete all images except the 4 newest:
./clean_old_versions --image 'busybox/busy' --include '*' -l 4

But this gave me:

Traceback (most recent call last):
  File "./clean_old_versions", line 86, in <module>
    main()
  File "./clean_old_versions", line 52, in main
    auth=auth, verify=args.no_check_certificate)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/_catalog (Caused by <class 'socket.error'>: [Errno 111] Connection refused)

Any help on this issue? Thanks

Hi, I can't help you with your original question but the registry does support garbage collection as of version 2.4 (2.5 is the current one). Maybe it is sufficient for your needs?

https://github.com/docker/distribution/blob/master/docs/garbage-collection.md

Thanks @donnex . I'm now exploring it. It seems to clean thins up in a nice way after I remove the manifest manually (rm -r inside the container). Do you know a better way how to delete a manifest (based on tag) of an image?. I saw this but it's unsupported:

curl -XDELETE http://myreg:5000/v2/proj1/base/manifests/1.0
{"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}

Yeah, you have to enable storage delete in the repository. I'm using env vars to enable it by setting REGISTRY_STORAGE_DELETE_ENABLED: "true". When I enabled this setting I could delete images with the API and then run the garbage collection.

https://github.com/docker/distribution/blob/master/docs/configuration.md

delete

Use the delete subsection to enable the deletion of image blobs and manifests by digest. It defaults to false, but it can be enabled by writing the following on the configuration file:

delete:
enabled: true

@donnex Thanks, I've started my registry with that variable.
Am I able to delete the image based on the tag? So deleting the manifest based on the tag and than run the GC?
I tried this to delete the manifest but does not seem to work (I hope I don't have to GET the tag and delete the manifests manually?):

curl -XDELETE http://my-reg:5000/v2/proj1/base/manifests/1.0
{"errors":[{"code":"DIGEST_INVALID","message":"provided digest did not match uploaded content"}]}
and
$ curl -XDELETE http://my-reg:5000/v2/proj1/base/manifests/tags/1.0
404 page not found

@lorenzvth7 i've added an "Alternatives" section to the bottom of the README with a link to a docker issue that describes a process you can use to delete by tag. Thanks for pointing out this new alternate path to registry cleanliness, @donnex .

Regarding the error in this issue, I can replicate that by specifying a bad registry_url. Note that the default is "http://localhost". I've written a test that demonstrates usage of clean_old_versions.py. Note the --registry-url http://localhost:5000 and the --include '.*' instead of --include '*'.