Last active
April 8, 2018 16:15
-
-
Save ironpinguin/cbe7335411baf528b82c293867d51c1e to your computer and use it in GitHub Desktop.
cleanup_docker_registry_after_gc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REGISTRY_BASE_PATH="/var/lib/registry" | |
REGISTRY_DATA_PATH="${REGISTRY_BASE_PATH}/docker/registry/v2/" | |
for hashLinkFile in `ls ${REGISTRY_DATA_PATH}/repositories/*/_layers/*/*/link`; do | |
hashType=`cat $hashLinkFile | cut -d':' -f1` | |
hashValue=`cat $hashLinkFile | cut -d':' -f2` | |
blob="store/docker/registry/v2/blobs/${hashType}/${hashValue:0:2}/${hashValue}/data" | |
if [ ! -f $blob ]; then | |
rm $hashLinkfile | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
registry_url="localhost:5000" | |
CONTAINER=$1 | |
if [ $CONTAINER == '' ]; then | |
echo "Please give container to remove" | |
exit 1 | |
fi | |
image=${CONTAINER%:*} | |
tag="latest" | |
if [[ $CONTAINER =~ : ]]; then | |
tag=${CONTAINER#*:} | |
fi | |
get_digest() { | |
curl -fsS -I \ | |
-H'Accept: application/vnd.docker.distribution.manifest.v2+json' \ | |
${registry_url}/v2/${image}/manifests/${tag} | | |
grep Docker-Content-Digest | | |
awk '{print $2}' | |
} | |
curl -fsS -X DELETE ${registry_url}/v2/${image}/manifests/`get_digest` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment