DEV Community

Keff
Keff

Posted on

Docker Registry v2 Cleanup?

If you use Docker you will know that it clogs your disk space rather quickly. We use it in most of our projects, with our own Registry. But the thing is, it clogs up the disk space with obsolete blobs, digests, and manifests... We had over 1 TB of obsolete stuff...

We have been trying to find an official way of cleaning the registry up, we have found GarbajeCollector although it only works if you remove the references by hand, then it removes the blobs.

My question is, any of you have been able to completely automate the removal of outdated Images aka blobs in the Registry? Or if not, is there any good tool out there?

EDIT:

My colleague got it working with GarbajeCollector in the end, although it only works with registry > 2.7 & passing -m flag.

If you have the same problem and need more info please let me now!

Top comments (8)

Collapse
 
vepo profile image
Victor Osório

Are you talking about your local machine or you docker registry?

If you are asking about your local machine, you can use docker system prune -a .
It will remove everything that is not usedb by your running containers.

Collapse
 
nombrekeff profile image
Keff

Our registry, I will specify it in the post for other readers also.

Collapse
 
vepo profile image
Victor Osório

Nice!
I have the same problem in the past, but when I was using Amazon ECR.

So for solving this problem I made a script and installed it on a crontab.

#!/bin/bash
REPOS=$(aws ecr describe-repositories --region sa-east-1 --query ‘repositories[].repositoryName’ --output text)
for repo in $REPOS; do
    TAGS=$(aws ecr list-images --region sa-east-1 --repository-name $repo --filter tagStatus=UNTAGGED --query ‘imageIds[].imageDigest’ --output text)
    for tag in $TAGS; do
        echo “Deleting image: $tag”
        aws ecr batch-delete-image --region sa-east-1 --repository-name $repo --image-ids imageDigest=$tag
    done
done
Thread Thread
 
vepo profile image
Victor Osório

This solution is for ECR, but you can build a similar solution for your server.

Thread Thread
 
nombrekeff profile image
Keff

Nice, If we don't find an official way we will definitely be using this or inspiring from it, thanks for sharing :)

Collapse
 
devdrake0 profile image
Si

What specifically are you trying to remove? Dead/unused images, or do you just want to nuke everything and start again?

Collapse
 
nombrekeff profile image
Keff • Edited

Yup, dead/unused images, and all related digests and manifests, mostly all the outdated blobs as they are heavy in contrast with the manifests and digests.

Well, all unless the last 2 images actually, as to have one in case a quick rollback is needed.

Collapse
 
nombrekeff profile image
Keff

My colleague got it working with GarbajeCollector in the end, although it only works with registry > 2.7 & passing -m flag.

If you have the same problem and need more info please let me now!