Skip to content

Instantly share code, notes, and snippets.

@jc1arke
Created May 31, 2018 05:42
Show Gist options
  • Select an option

  • Save jc1arke/bb84f47baa7cd8262efb559a6ef6b3bb to your computer and use it in GitHub Desktop.

Select an option

Save jc1arke/bb84f47baa7cd8262efb559a6ef6b3bb to your computer and use it in GitHub Desktop.
Quick cleanup of images for a namespace on a private Docker registry
#!/usr/bin/env bash
DOCKER_IMAGE_NAMESPACE=$1
DOCKER_REGISTRY=${DOCKER_REGISTRY:-registry.docker.lan}
readarray -t tags < <(curl -H “Accept: application/vnd.docker.distribution.manifest.v2+json” http://$DOCKER_REGISTRY/v2/${DOCKER_IMAGE_NAMESPACE}/tags/list | jq “.tags” | jq -r -c ‘to_entries | .[].value’)
for tag in “${tags[@]}”
do
echo “Removing tag $tag for $DOCKER_IMAGE_NAMESPACE”
docker_image_sha=$(curl --silent -I -H “Accept: application/vnd.docker.distribution.manifest.v2+json” -H “Content-Type: application/json” http://$DOCKER_REGISTRY/v2/$DOCKER_IMAGE_NAMESPACE/manifests/$tag | awk ‘$1 == “Docker-Content-Digest:” { print $2 }’ | tr -d $’\r’)
echo “docker_image_sha: $docker_image_sha”
curl -X DELETE -H “Accept: application/application/vnd.docker.distribution.manifest.v2+json” http://$DOCKER_REGISTRY/v2/${DOCKER_IMAGE_NAMESPACE}/manifests/${docker_image_sha}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment