Skip to content

Instantly share code, notes, and snippets.

@haolian9
Last active November 24, 2017 06:22
Show Gist options
  • Save haolian9/4f5a92a7c1b85613be8fd1c511f992eb to your computer and use it in GitHub Desktop.
Save haolian9/4f5a92a7c1b85613be8fd1c511f992eb to your computer and use it in GitHub Desktop.
shell script that lists all tags of a given image, inspired by [answer](https://stackoverflow.com/a/39454426)
#!/usr/bin/env bash
image="$1"
if [ -z "$image" ]; then
echo "usage: script-name full-image-name"
exit 1
fi
declare -A tags
for i in $(wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - \
| python -m json.tool \
| sed -n '/name/p' | awk '{ print $2 }' | tr -d '"' \
| sort -h | uniq);
do
tag_index="$(expr $i : '\(^[0-9a-zA-Z]\+\)')"
tags["$tag_index"]=$(echo "${tags[$tag_index]}, ${i}" | sed 's/^, //')
done
for j in "${tags[@]}"; do
echo $j
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment