Skip to content

Garbage collect deletes blobs in disk but blobs are still in memory and registry does not accept the push twice #4569

Closed

Description

@DanielVenturini

Description

By default conf.yml has the following configuration set, which keeps blob descriptors in memory:

storage:
  cache:
    blobdescriptor: inmemory

Image tag deletion process deletes blobs and layers from disk, but does not delete in memory descriptors.
Due to in memory descriptors, it's not possible to re-push the same image because registry uses cache layers but such layers are not there actually.

Reproduce

reproducable in both latest V3 (`3.0.0-rc.2) and V2; I'll use V3 in this example

When a image is pushed into the registry, deleted and garbage collect is executed, the blobs are fully removed from disk:

# start a registry
docker run -d -e REGISTRY_STORAGE_DELETE_ENABLED=true -p 5000:5000 --rm --name registry-in-memory-blobs registry:3.0.0-rc.2

# creating a random tag and push it
docker tag registry:3.0.0-rc.2 localhost:5000/registry:3.0.0-rc.2
docker push localhost:5000/registry:3.0.0-rc.2

# then delete the tag and run garbage collect
curl -X DELETE http://localhost:5000/v2/registry/manifests/sha256:776203b7933004f7b6cada731e171469e3e267a1e77912fd8e0fc26c16f896f2
docker exec registry-in-memory-blobs /bin/registry garbage-collect /etc/distribution/config.yml

Previous commands successfully deleted blobs from disk, but their descriptions are still in memory.

When the same push takes place again, registry says blobs/layers are already there and does not really accept the push, but uses the cache layers instead of pushing:

docker push localhost:5000/registry:3.0.0-rc.2
# 2b07afdb0755: Layer already exists 
# 55659e28f40e: Layer already exists 
# 6323af7fd13e: Layer already exists 
# d73b26c48fce: Layer already exists 
# a0904247e36a: Layer already exists 
# 3.0.0-rc.2: digest: sha256:776203b7933004f7b6cada731e171469e3e267a1e77912fd8e0fc26c16f896f2 size: 1364

But no new layers were created on disk, and if we try to pull it will not work:

docker pull localhost:5000/registry:3.0.0-rc.2
# Error response from daemon: manifest for localhost:5000/registry:3.0.0-rc.2 not found: manifest unknown: manifest unknown

So, the HTTP DELETE request and garbage collect successfully deleted the blobs and layers from disk, but haven't deleted the in memory blob descriptors. It makes inconsistency between what is in memory and what is in disk.

If the blobdescriptor: inmemory is not set, them this behavir does not happen

Expected behavior

registry allows to push the same image after deleting it

registry version

3.0.0-rc.2

Additional Info

No response

Activity

  1. Ollegio commented on Mar 10, 2025

    @Ollegio

    similar issue here #4525
    they said nothing about cache, but I think it should be the same problem, also possible solution
    #4525 (comment)

  2. milosgajdos commented on Mar 10, 2025

    @milosgajdos
    Member

    Think we need this to get over the finish line #3323

  3. milosgajdos commented on Mar 10, 2025

    @milosgajdos
    Member

    @Ollegio feel free to open a new PR; I'm happy to review it and push it through.

  4. dkvrgic commented on Apr 17, 2025

    @dkvrgic

    Hi guys, I am using registry image v3.0.0 official one , this behavior is still happening. I need to restart the registry container after garbage-collect cmd being executed in order to prevent this. Any feedback on this issue ??

  5. DanielLeone commented on Dec 15, 2025

    @DanielLeone

    Confirming this is still a problem for me for both v2 and v3 registry, here's the smallest test script I've got:

    # run a local registry
    docker rm -f local-registry
    docker run -d --name local-registry -p 6000:5000 -e REGISTRY_STORAGE_CACHE_BLOBDESCRIPTOR=inmemory -v "$(pwd)/private-registry:/var/lib/registry" registry:2.8.3
    
    # create a simple dockerfile with a few shared layers between 2 images
    cat > Dockerfile <<'EOF'
    FROM busybox:1.36 AS base
    WORKDIR /out
    RUN printf 'a' > a
    RUN printf 'b' > b
    RUN printf 'c' > c
    
    FROM base AS image-one
    RUN printf 'd-1' > d
    CMD ["true"]
    
    FROM base AS image-two
    RUN printf 'd-2' > d
    CMD ["true"]
    EOF
    
    # build both images
    docker build -t localhost:6000/test:image-one --target image-one .
    docker build -t localhost:6000/test:image-two --target image-two .
    
    # tag, push and pull image one as latest
    docker tag localhost:6000/test:image-one localhost:6000/test:latest
    docker push localhost:6000/test:latest
    docker pull localhost:6000/test:latest
    
    # tag, push and pull image two over the top
    docker tag localhost:6000/test:image-two localhost:6000/test:latest
    docker push localhost:6000/test:latest
    docker pull localhost:6000/test:latest
    
    # run garbage collection
    docker exec local-registry registry garbage-collect -m /etc/docker/registry/config.yml
    
    # repush image one back over the top of image two
    docker tag localhost:6000/test:image-one localhost:6000/test:latest
    docker push localhost:6000/test:latest
    
    # pull is broken, only when the cache is enabled on the registry
    docker pull localhost:6000/test:latest

    v3 exhibits the same failure with the same script, just needs the config path changed

    # run a local registry
    docker rm -f local-registry
    docker run -d --name local-registry -p 6000:5000 -e REGISTRY_STORAGE_CACHE_BLOBDESCRIPTOR=inmemory -v "$(pwd)/private-registry:/var/lib/registry" registry:3.0.0
    
    # create a simple dockerfile with a few shared layers between 2 images
    cat > Dockerfile <<'EOF'
    FROM busybox:1.36 AS base
    WORKDIR /out
    RUN printf 'a' > a
    RUN printf 'b' > b
    RUN printf 'c' > c
    
    FROM base AS image-one
    RUN printf 'd-1' > d
    CMD ["true"]
    
    FROM base AS image-two
    RUN printf 'd-2' > d
    CMD ["true"]
    EOF
    
    # build both images
    docker build -t localhost:6000/test:image-one --target image-one .
    docker build -t localhost:6000/test:image-two --target image-two .
    
    # tag, push and pull image one as latest
    docker tag localhost:6000/test:image-one localhost:6000/test:latest
    docker push localhost:6000/test:latest
    docker pull localhost:6000/test:latest
    
    # tag, push and pull image two over the top
    docker tag localhost:6000/test:image-two localhost:6000/test:latest
    docker push localhost:6000/test:latest
    docker pull localhost:6000/test:latest
    
    # run garbage collection
    docker exec local-registry registry garbage-collect -m /etc/distribution/config.yml
    
    # repush image one back over the top of image two
    docker tag localhost:6000/test:image-one localhost:6000/test:latest
    docker push localhost:6000/test:latest
    
    # pull is broken now for image one only when the cache is enabled
    docker pull localhost:6000/test:latest
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