Skip to content

Instantly share code, notes, and snippets.

@steimntz
Last active April 5, 2018 20:48
Show Gist options
  • Save steimntz/6886c64187ce7d8e86bbe4cea669b696 to your computer and use it in GitHub Desktop.
Save steimntz/6886c64187ce7d8e86bbe4cea669b696 to your computer and use it in GitHub Desktop.
Ten liner for deleting images from a v2 docker registry

A ten liner for deleting images from a v2 docker registry

I use bash and jq to create that script.

The script

#!/usr/bin/env bash
reg=$1
repo=$2
allTags=$(curl -sSLH 'Accept: application/vnd.docker.distribution.manifest.v2+json' http://$reg/v2/$repo/tags/list | jq '.tags' | grep -oP '[^",\[\]\n\s]+')
while read -r tag; do
        echo "The following tags will be removed"
        echo "$tag"
        digest=$(curl -sSL -I -H "Accept: application/vnd.docker.distribution.manifest.v2+json" http://$reg/v2/$repo/manifests/$tag | awk '$1 == "Docker-Content-Digest:" { print $2 }' | tr -d $'\r')
        curl -v -sSL -X DELETE "http://$reg/v2/$repo/manifests/$digest"
done <<< "$allTags"

How to use it

./reg.sh meuregistro:5000 myfuckingproject

The script is based in this Gist - One liner for deleting images from a v2 docker registry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment