Skip to content

Instantly share code, notes, and snippets.

@efrecon
Last active April 16, 2018 08:15
Show Gist options
  • Save efrecon/4d1334dcb98177bc23af1edd616b4281 to your computer and use it in GitHub Desktop.
Save efrecon/4d1334dcb98177bc23af1edd616b4281 to your computer and use it in GitHub Desktop.
List all the tags for a given image at the Docker hub
#!/bin/sh
# Inspired by: https://stackoverflow.com/a/43262086, tested on Ubuntu and Alpine
if [ -z "$1" ]; then
echo "You have to provide an image name!"
exit
fi
if [ -z "$(echo "$1" | grep -o '/')" ]; then
hub="https://hub.docker.com/r/library/$1/tags/"
else
hub="https://hub.docker.com/r/$1/tags/"
fi
resp="Page Not Found"
if [ -z "$(command -v curl)" ]; then
resp=$(wget -q -O - $hub)
else
resp=$(curl -sL $hub)
fi
err=$(echo "$resp"|grep -o "Page Not Found")
if [ -n "$err" ]; then
echo "Cannot find image $1!"
exit
else
tags="$(echo "$resp"|sed -e 's|}|\n|g' -e 's|{|\n|g'|grep '"result"'|sed -e 's|,|\n|g'|cut -d '[' -f2|cut -d ']' -f1|sed '/"tags":/d'|sed -e 's|"||g')"
echo $tags
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment