Skip to content

Instantly share code, notes, and snippets.

@cuishuaigit
Last active December 14, 2018 10:35
Show Gist options
  • Save cuishuaigit/34439b8946821c7898d1faefbf5bdbb1 to your computer and use it in GitHub Desktop.
Save cuishuaigit/34439b8946821c7898d1faefbf5bdbb1 to your computer and use it in GitHub Desktop.
clean docker registry
#!/bin/bash
#docker private registry clean imag that five days ago
#repositories dir
dir="/data/registry/data/docker/registry/v2/repositories/"
a="/_manifests/tags"
#link a full addr
while getopts ":g:p:l:h:t:" opt
do
case $opt in
g)
dir_tag1=$dir$OPTARG
;;
p)
dir_tag2=$dir_tag1/$OPTARG
dir_tag=$dir_tag2$a
;;
l)
dir_tag3=$dir_tag2/$OPTARG
dir_tag=$dir_tag3$a
;;
t)
b=$OPTARG
;;
?)
echo "if your url have three layers like: https://<url>/fireball/saturn
$0 -g(group) -p(project) -t(time,if not set default is 5)"
echo "if your url have three layers like: https://<url>/fireball/test/saturn
$0 -g(group) -l -p(project -t(time,if not set default is 5))"
exit 1;;
esac
done
#---------------------------------------------------------------------------------------------------------#
cd $dir_tag
#date that to find,the default is 5
tm=${b:-5}
#find all of dgists that meet the requirements
dgists=`find . -name link -mtime +$tm | grep current|xargs grep "sha256" | awk -F ":" '{print $3}'`
#delet dgists
for i in $dgists
do
echo $i
curl -k -I -X DELETE https://huou:histry@localhost:5000/v2/fireball/saturn/manifests/sha256:$i
done
#delete true data,use garbage-collect
if [ $? -eq 0 ];then
docker exec -it registry /bin/registry garbage-collect /etc/docker/registry/config.yml
fi
@cuishuaigit
Copy link
Author

Usage:
interaction-clean -h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment