Created
July 16, 2019 17:51
-
-
Save fitz123/91f85e7f25fcfc91b64a6ce8a0eaf10e to your computer and use it in GitHub Desktop.
Delete docker image:tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
set -x | |
fullimage=${IMAGE:-$1} | |
image=${fullimage##*/} | |
repo=${image%%:*} | |
tag=${image##*:} | |
REG=${fullimage%%/*} | |
PROTO=https:// | |
set +x | |
curl -fSIso /dev/null -H "Accept:application/vnd.docker.distribution.manifest.v2+json" "$PROTO$REG/v2/$repo/manifests/$tag" | |
response=$(curl -v -s -H "Accept:application/vnd.docker.distribution.manifest.v2+json" "$PROTO$REG/v2/$repo/manifests/$tag" 2>&1) | |
digest=$(echo "$response" | grep -i "< Docker-Content-Digest:"|awk '{print $3}') | |
digest=${digest//[$'\t\r\n']} | |
echo "DIGEST: $digest" | |
result=$(curl -s -o /dev/null -w "%{http_code}" -H "Accept:application/vnd.docker.distribution.manifest.v2+json" -X DELETE "$PROTO$REG/v2/$repo/manifests/$digest") | |
if [ $result -eq 202 ]; then | |
echo "Successfully deleted" | |
exit 0 | |
else | |
echo "Failed to delete: $result" | |
exit 3 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment