Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created April 28, 2022 12:07
Show Gist options
  • Save gmolveau/72ab3e3ef89f598f614eca8a92a88ef1 to your computer and use it in GitHub Desktop.
Save gmolveau/72ab3e3ef89f598f614eca8a92a88ef1 to your computer and use it in GitHub Desktop.
nexus docker registry delete image by tag
#!/bin/bash
# inspiration/source : https://gist.github.com/matzegebbe/a2678b227add6bafad9a3a802618b5ad + https://issues.sonatype.org/browse/NEXUS-12711
NEXUS_HOST="nexus.domain.tld"
NEXUS_REPOSITORY="docker"
NEXUS_USER="service"
NEXUS_PASSWORD="password"
IMAGE="python"
TAG="latest"
SHA256=$(curl --head -s -L -k -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -u "$NEXUS_USER:$NEXUS_PASSWORD" "http://$NEXUS_HOST/repository/$NEXUS_REPOSITORY/v2/$IMAGE/manifests/$TAG" | grep "docker-content-digest" | cut -d ":" -f3 | tr -d '\r')
STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" -k -L -X DELETE -u "$NEXUS_USER:$NEXUS_PASSWORD" "http://$NEXUS_HOST/repository/$REPOSITORY/v2/$IMAGE/manifests/sha256:$SHA256")
[ "$STATUS" != "202" ] && (
echo "status_code $STATUS != 202"
exit 1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment