Skip to content

Registry ignores re-push of GC'd blobs unless restarted #1803

Open

Description

@mikenel

I am using Registry v2.4.1.

When I delete an image, run garbage collection, and try to push the same image, Registry thinks that the layers are already present and doesn't ask the client to upload them again. There are no other images in the registry and the blob directories under /var/lib/registry/... are empty in my test registry. I am guessing that some in-memory blob tracking cache needs to be invalidated after garbage collection.

Delete, GC, and try to push:

# curl -XDELETE http://localhost:5000/v2/test1/manifests/sha256:e74b1feff383713dc90402b092a7db6d7f1039ccbc88565e7ee959afba93066b
# docker exec -ti registry2 /bin/registry garbage-collect /etc/docker/registry/config.yml
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/14/14e6410efe488c623ffd79a858567ae742ab2c4a23b7197fcf4e67d765bac2c6  go.version=go1.6.2 instance.id=b357c178-221b-49a7-8b91-6dc7da415a3d
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/82/82d2c12b1cdaba861e8be79e39cb23eee889d778f88268e62883f19b83039ae4  go.version=go1.6.2 instance.id=b357c178-221b-49a7-8b91-6dc7da415a3d
[...]

# docker push 127.0.0.1:5000/test1:v2
The push refers to a repository [127.0.0.1:5000/test1]
622d280fe41e: Layer already exists
7503f970aad3: Layer already exists
2371c1731b0a: Layer already exists
e5fd538c8c98: Layer already exists
[...]

No blobs are present on disk:

# du -s docker/registry/v2/blobs

4       docker/registry/v2/blobs/sha256/14
4       docker/registry/v2/blobs/sha256/e0
4       docker/registry/v2/blobs/sha256/bc
4       docker/registry/v2/blobs/sha256/22
4       docker/registry/v2/blobs/sha256/e7
4       docker/registry/v2/blobs/sha256/04
4       docker/registry/v2/blobs/sha256/89
[...]

Restart Registry after delete and push again:

# docker restart registry2
registry2
# docker push 127.0.0.1:5000/test1:v2
The push refers to a repository [127.0.0.1:5000/test1]
622d280fe41e: Pushed
56dc8d9cf120: Pushing [>                                                  ] 1.641 MB/367 MB
[...]

Activity

  1. added this to the Registry/2.5 milestone on Jun 27, 2016
  2. RichardScothern commented on Jun 27, 2016

    @RichardScothern

    Your analysis is correct @mikenel. However, before running a garbage collection, the registry should be in read-only mode (which requires a restart) or not running at all. If this doesn't happen you are at risk of losing data by writing data to the registry while garbage collection is running.

  3. fsword commented on Dec 10, 2016

    @fsword

    @RichardScothern I dont think this is the right way for registry. Restart is used at console, so its is not a suitable way for admin. Somebody may think registry should be used as a docker container, but container restart is a operation on devops platform ( eg. mesos/k8s ) , we cannot suppose that registry admin is a user of that.

    So, if we use registry in the right way, the registry should be maintained by admin without restart, and admin make the choise of when to GC.

  4. removed this from the Registry/2.6 milestone on Dec 20, 2016
  5. dmcgowan commented on Dec 20, 2016

    @dmcgowan
    Collaborator

    I don't think this is the right way for registry

    Our desire is to have a better garbage collector which does not require a restart. Implementing this is blocked on a few other features, including having metadata stored in a transactional database. Until we get to that point, the registry must be brought up in read-only mode to ensure no writes are happening. We are not opinionated in how to operationalize this restart just noting the risks of having concurrent write operations on the backend and the requirement on read-only mode on the registry process. If you have a method that has worked well for you please share.

  6. fsword commented on Dec 24, 2016

    @fsword

    @dmcgowan Yes, it's also one of the reasons I said that. But I'm not good at golang and not familiar with docker registry......

    If you need a PR for this issue, maybe you can pay for it. I can pay 0.1 BTC for it.

  7. stevvooe commented on Jan 10, 2017

    @stevvooe
    Collaborator

    I suspect that this is the same issue as #2094.

  8. dentych commented on Apr 9, 2019

    @dentych

    Any news on this? It is still an issue, and it seems to have died off a little?..

  9. gwaines commented on Apr 17, 2019

    @gwaines

    We just tried on current version of docker and still seems to require a registry restart.

  10. jimmytoan commented on Oct 24, 2020

    @jimmytoan

    I found that the last push does not upload layer to registry, because the registry shows Layer already exists. It caused by the cache (in memory or redis)
    I'm able to confirm it by 2 different settings of registry on Kubernetes
    Case 1: configure registry to use in memory cache (default settings). Re-create registry pod before pushing. It works
    Case 2: configure registry to user redis cache. Re-create redis pod before pushing. It works

    Note: I still do not figure out how to clear the registry cache right after delete tags and garbage collection

  11. ziXet commented on Apr 5, 2021

    @ziXet

    I have the same issue! registry service must be restarted for inmemory cache

  12. deleteriousEffect commented on Apr 5, 2021

    @deleteriousEffect
    Member

    Garbage collection could potentially clear a Redis cache, but I don't see a way to clear an inmemory cache, since garbage collection runs in a separate process, so it wouldn't have access to an inmemory cache of a running registry.

  13. milosgajdos commented on Apr 21, 2021

    @milosgajdos
    Member

    Probably related #3322

  14. added 2 commits that reference this issue on Apr 13, 2026
    a241145
    df7deaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions