DEV Community

Discussion on: Docker Registry v2 Cleanup?

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 :)