Skip to content

Instantly share code, notes, and snippets.

@neilmillard
Forked from paulrobello/cleanup.sh
Last active June 13, 2018 09:24
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 neilmillard/0d6ef3dbd8973697d3c326e95fcf9cdc to your computer and use it in GitHub Desktop.
Save neilmillard/0d6ef3dbd8973697d3c326e95fcf9cdc to your computer and use it in GitHub Desktop.
Docker registry v2 cleanup script
#!/bin/bash
### your registry must have the following environment var set
# REGISTRY_STORAGE_DELETE_ENABLED=true
### replace YOUR_SERVER with corect info
REGISTRY_URL=https://YOUR_SERVER:5000
### host registry volume folder
REGISTRY_ROOT=/registry
### container to execute garbage-collect
CONTAINER_NAME=services_registry.1
### config file used by your registry
REG_CONFIG=/etc/docker/registry/config.yml
### number of most recent digests to keep
NUM_DIGEST_KEEP=3
### tag to check
TAG=latest
if ! [ -r $REGISTRY_ROOT ]; then
echo registry root $REGISTRY_ROOT not readable
exit;
fi
CONTAINER=`docker ps | grep $CONTAINER_NAME | cut -d' ' -f1`
if [ -z $CONTAINER ]; then
echo container $CONTAINER_NAME not found
exit 1
fi
for repo in `ls $REGISTRY_ROOT/docker/registry/v2/repositories` ; do
echo $repo
DIR=$REGISTRY_ROOT/docker/registry/v2/repositories/$repo
cd $DIR
for hash in $(find . -mindepth 6 -maxdepth 6 | cut -d/ -f7) ; do
echo $hash
curl -X DELETE $REGISTRY_URL/v2/$repo/manifests/sha256:$hash;
done
cd -
done
docker exec $CONTAINER /bin/registry garbage-collect $REG_CONFIG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment