genuinetools / reg

Docker registry v2 command line client and repo listing generator with security checks.
https://r.j3ss.co
MIT License
1.66k stars 172 forks source link

Deleting images #166

Open jjo93sa opened 5 years ago

jjo93sa commented 5 years ago

Hi, perhaps I'm doing something wrong, but I can't get reg to delete an image, despite running garbage collection after issuing the command.

I'm trying to delete an alpine image from a registry, so I retrieve the manifest like this:

{ "schemaVersion": 2, "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "config": { "mediaType": "application/vnd.docker.container.image.v1+json", "size": 1512, "digest": "sha256:196d12cf6ab19273823e700516e98eb1910b03b17840f9d5509f03858484d321" }, "layers": [ { "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "size": 2206931, "digest": "sha256:4fe2ade4980c2dda4fc95858ebb981489baec8c1e4bd282ab1c3560be8ff9bde" } ] }

I've tried using both digests, in both cases, I receive a response message like this:

Deleted /alpine@sha256:196d12cf6ab19273823e700516e98eb1910b03b17840f9d5509f03858484d321

The image is still listed, before and after manually initiating garbage collection on the repository:

Repositories for REPO TAGS alpine latest

The registry Env contains "REGISTRY_STORAGE_DELETE_ENABLED=true", which I believe is required to delete images? Am I doing something fundamentally stupid here?

tomsherrod commented 5 years ago

I found that "reg digest registry/repo/alpine:tag" will give the sha needed for deletion. This sha should match the sha at the end of "docker push registry/repo/alpine:tag". A garbage-collect did remove the blobs.

A bit of a shortcut that I've been using: "reg rm registry/repo/alpine:tag" All in one command.

jjo93sa commented 5 years ago

@tomsherrod Thanks for the tip - this partially works for me; I can delete the tags (and something was garbage collected when I manually executed it) but I find the repo is still listed, but this time with no tags. For example:

docker run reg ls <repo>
REPO                     TAGS
alpine                     test

then delete:

docker run reg rm -u <user> -p <pass> <repo>/alpine:test

then list again:

docker run reg ls <repo>
REPO                     TAGS
alpine

So, the image is still listed, just now with no tags. I had expected if an image has no tags it would no longer be listed?

The reg version I'm running to perform the deletion is quite old, I usually pull from r.j3ss.co but that isn't working at the moment, the page says "Getting tags for reg failed". Co-incidentally, that is exactly the same message I observe when I click on the alpine repo link generated in the static webpage built for me by reg after I've used your method to delete the image from my registry. (The static webpage is built by an equivalently old version of reg)

I haven't had time to build my own reg to test a newer version, and I don't know (& haven't been able to determine) if this is a "docker:registry" or a "reg static webpage" issue.

I'll test again with a newer version of reg as soon as I can pull/build one & real life permits. Sorry to everyone if I'm doing something wrong.

glitchcrab commented 5 years ago

@jjo93sa i'd be interested to know if you got any further with this - I'm running the latest registry image (with delete enabled) and reg v0.16.0 and i'm left with a bunch of dangling repos with no tags too.

jjo93sa commented 5 years ago

@jjo93sa i'd be interested to know if you got any further with this - I'm running the latest registry image (with delete enabled) and reg v0.16.0 and i'm left with a bunch of dangling repos with no tags too.

@glitchcrab haven't tested deleting again since my 21 Mar post. I'm intending to delete my repo and test with a brand new one, in case something is awry. Just need to find the time.

jjo93sa commented 5 years ago

@glitchcrab I nuked my registry, rebuilt it, pushed a test image and then deleted it in a couple of ways:

Both methods I get dangling repos, that is repos listed without any tags:

$ docker run r.j3ss.co/reg ls r.j2o.it
time="2019-05-30T15:54:25Z" level=info msg="domain: r.j2o.it"
time="2019-05-30T15:54:25Z" level=info msg="server address: r.j2o.it"
Repositories for r.j2o.it
REPO                     TAGS
centos         

I can't work out how to tell if this is an "instrumentation problem" i.e. that reg is listing the repo incorrectly (dangling repo appears both in the static web page and with reg ls) or if it is a docker registry problem that it isn't cleaning up repos without tags. What I do know is that listing the registry after manually triggering garbage collection does not change matters - the dangling repo still exists.

Really happy to help debug this, if anyone has some suggestions.

glitchcrab commented 5 years ago

@jjo93sa your tests on a clean registry mirror my experiences, but I'm also unable to determine whether it's issue with Reg or the registry itself.