Skip to content

Instantly share code, notes, and snippets.

@ruxkor
Created August 2, 2018 13:52
Show Gist options
  • Save ruxkor/796ebc2866581195c36110f85e8712c8 to your computer and use it in GitHub Desktop.
Save ruxkor/796ebc2866581195c36110f85e8712c8 to your computer and use it in GitHub Desktop.
delete a specific image in your docker registry
#!/bin/bash
# set the following variables
REGISTRY_HOSTNAME=
REGISTRY_USER=
REGISTRY_PASSWORD=
REGISTRY_IMAGE=
REGISTRY_IMAGE_TAG=
# if you don't know, get the tags first
# curl -sSL "https://${REGISTRY_USER}:${REGISTRY_PASSWORD}@${REGISTRY_HOSTNAME}/v2/${REGISTRY_IMAGE}/tags/list" | jq -r '.tags'
REGISTRY_IMAGE_DIGEST=$(curl -sSL -I -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "https://${REGISTRY_USER}:${REGISTRY_PASSWORD}@${REGISTRY_HOSTNAME}/v2/${REGISTRY_IMAGE}/manifests/${REGISTRY_IMAGE_TAG}" | awk '$1 == "docker-content-digest:" { print $2 }' | tr -d $'\r')
curl -v -sSL -X DELETE "https://${REGISTRY_USER}:${REGISTRY_PASSWORD}@${REGISTRY_HOSTNAME}/v2/${REGISTRY_IMAGE}/manifests/${REGISTRY_IMAGE_DIGEST}" 2>&1 | grep '< HTTP'
# should return 204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment