Skip to content

Instantly share code, notes, and snippets.

@immanuelpotter
Last active June 29, 2018 08:33
Show Gist options
  • Save immanuelpotter/8d5dd410d26ecc0e8994d0e595f471e7 to your computer and use it in GitHub Desktop.
Save immanuelpotter/8d5dd410d26ecc0e8994d0e595f471e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set this in your env:
REGISTRY=<ip addr>
# Get a registry going:
docker run -d -p 5000:5000 --name registry \
-v /var/lib/docker-registry:/var/lib/registry \
-e REGISTRY_STORAGE_DELETE_ENABLED=true \
--restart=always \
<registry-ip-address>:5000/registry:2
# Get repositories
curl -sSL http://${REGISTRY}:5000/v2/_catalog
# Pull everything in the registry
for REPO in $(curl -sSL http://${REGISTRY}:5000/v2/_catalog | \
jq -r '.repositories[]') ; do docker pull -a $REPO ; done
# Get all tags for an image:
curl -sSL http://${REGISTRY}:5000/v2/<image-name>/tags/list
# Comprehensive list of all images and their corresponding tags, docker CLI-friendly output
for i in $(curl -sSL http://${REGISTRY}/v2/_catalog | jq -r '.repositories[]'))
do curl -sSL http://${REGISTRY}/v2/${i}/tags/list | \
jq -r --arg REGISTRY $REGISTRY/ '$REGISTRY + .name + ":" .tags[]'; done
# Delete an image, and then garbage collect (taken from https://gist.github.com/jaytaylor/86d5efaddda926a25fa68c263830dac1 )
name='my-image'
curl -v -sSL -X DELETE "http://${REGISTRY}/v2/${name}/manifests/$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"http://${REGISTRY}/v2/${name}/manifests/$(
curl -sSL "http://${REGISTRY}/v2/${name}/tags/list" | jq -r '.tags[0]'
)" | awk '$1 == "Docker-Content-Digest:" { print $2 }' |\
tr -d $'\r' \
)" ; docker exec -it registry bin/registry garbage-collect /etc/docker/registry/config.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment