Skip to content

Instantly share code, notes, and snippets.

@mping
Last active August 25, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mping/8e4f3dfafc40b2527ef3f5549f05bec6 to your computer and use it in GitHub Desktop.
Save mping/8e4f3dfafc40b2527ef3f5549f05bec6 to your computer and use it in GitHub Desktop.
Remove image from docker registry
def deleteImageWithTagAndHash(registryHost, imageName, tag, hash)
puts "Deleting..."
res = `curl -X DELETE -I http://#{registryHost}/v2/#{imageName}/manifests/#{hash}`
puts "curl -X DELETE -I http://#{registryHost}/v2/#{imageName}/manifests/#{hash}"
puts "Deleted image with tag #{tag}"
end
def getDigestForImageAndTag(registryHost, imageName, tag)
puts 'Processing...'
digestHash = `curl -s -I -X HEAD -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' http://#{registryHost}/v2/#{imageName}/manifests/#{tag} | sed -n 's/Docker-Content-Digest://p'`
puts "curl -s -I -X HEAD -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' http://#{registryHost}/v2/#{imageName}/manifests/#{tag} | sed -n 's/Docker-Content-Digest://p'"
digestHash.strip
end
def cleanup(registryHost)
def executeCleanup(registryHost) {
out = `DOCKER_API_VERSION=1.22 docker -H \"tcp://${registryHost}:2375\" exec -it docker-registry01 bin/registry garbage-collect /etc/docker/registry/config.yml`
out
}
end
hash = getDigestForImageAndTag("lismgtreg01.athepg.bskyb.com", "hapi-api", "2.0.1-SNAPSHOT-e62427aa2897380649456118741f0b2c6be1fbec")
deleteImageWithTagAndHash("lismgtreg01.athepg.bskyb.com", "hapi-api", "2.0.1-SNAPSHOT-e62427aa2897380649456118741f0b2c6be1fbec", hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment