Docker Registry Maintenance

December, 2017

Made this "clean-up" script after almost running out of disk space on the Docker registry.
Simply had too many snapshot / CI made / test versions!

The script (named will accept three parameters; registry URL, repository name and docker tag, and issue a DELETE request using curl.
Script should output "202 Accepted" on success.

The script was created and tested on Ubuntu 16.04 system.

# usage ./ <registry> <repository> <tag>
# eg.: ./ myrepo 1.0.42-SNAPSHOT


if [[ -z $REGISTRY ]] || [[ -z $REPO ]] || [[ -z $TAG ]];
  echo "Missing parameter(s) REGISTRY/REPOSITORY/TAG"
  echo ""
  echo "usage ./ <registry> <repository> <tag>"
  echo " eg.: ./ myrepo 1.0.42-SNAPSHOT"
  exit 1

# Get docker image hash
HASH=$(curl -sI -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' -X GET ${REGISTRY}/v2/${REPO}/manifests/${TAG} | grep "Docker-Content-Digest" | awk '{ print $2 }')

# Remove any \r from the delete URL, else curl would fail
DELETE_URL=$(echo "${REGISTRY}/v2/${REPO}/manifests/${HASH}" |sed -e "s/\r//")

# Delete docker image
curl -sI -X DELETE ${DELETE_URL} |grep "HTTP"

Now run the garbage collect.
It will mark and then delete unnecessary blobs from the docker repository:

docker exec my_registry bin/registry garbage-collect /etc/docker/registry/config.yml

Assumed that the registry container is named "my_registry" and the registry config file location is "/etc/docker/registry/config.yml"

The disk disk space should now be free !