Skip to content

Instantly share code, notes, and snippets.

@ironpinguin
Last active April 8, 2018 16:15
Show Gist options
  • Save ironpinguin/cbe7335411baf528b82c293867d51c1e to your computer and use it in GitHub Desktop.
Save ironpinguin/cbe7335411baf528b82c293867d51c1e to your computer and use it in GitHub Desktop.
cleanup_docker_registry_after_gc
#!/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
#!/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