Skip to content

Instantly share code, notes, and snippets.

@oxmix
Created June 8, 2023 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxmix/485283e965880fd89f3a0a0946169ef4 to your computer and use it in GitHub Desktop.
Save oxmix/485283e965880fd89f3a0a0946169ef4 to your computer and use it in GitHub Desktop.
Cleaner docker registry by only tag latest
#!/usr/bin/env bash
set -e
data="$(dirname "$0")/registry/data"
reg="$data/docker/registry/v2/repositories"
for n1 in $(ls $reg -t); do
for n2 in $(ls $reg/$n1 -t); do
repo=$n1/$n2
tag=$reg/$repo/_manifests/tags/latest/index/sha256
revs=$reg/$repo/_manifests/revisions/sha256
for hash in $(ls $tag -t | tail -n +2); do
echo "rm -> $repo -> $hash"
rm -rf $tag/$hash
rm -rf $revs/$hash
done
before=$(date -r $tag/$(ls -t $tag) +"%Y-%m-%d %H:%M:00")
find $revs/ -type d ! -newermt "$before" | xargs rm -rf
done
done
echo "exec garbage-collect"
docker exec -it ctr-ship.docker-registry bin/registry garbage-collect /etc/docker/registry/config.yml
du -md1 $data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment