Skip to content

Instantly share code, notes, and snippets.

@nooop3
Created May 28, 2018 01:17
Show Gist options
  • Save nooop3/4a89a4e1b70d73386ec418ad6bbfefc0 to your computer and use it in GitHub Desktop.
Save nooop3/4a89a4e1b70d73386ec418ad6bbfefc0 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
# echo -e '\e[31m[-]\e[39m usage:'
echo "usage: docker-tags [[[-p page ] [-a --all]] | [-h --help]]"
}
page=1
image=
all=0
if [ $# -eq 0 ]; then
usage
exit 1
fi
while [ $# -ne 1 ]; do
case $1 in
-p | --page ) shift
page=$1;
;;
-a | --all ) all=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
image=$1
# curl https://registry.hub.docker.com/v2/repositories/$image/tags/?page=$page 2>/dev/null|jq '."results"[]["name"]'
echo
echo "get image tags from docker.com, image: $image"
echo
prefix="https://registry.hub.docker.com/v2/repositories"
[[ ! -z "$(echo "$image" | grep -i '/')" ]] && { link="$prefix/$image" ; } || { link="$prefix/library/$image" ; }
link="$link/tags/?page=$page"
echo "curl $link"
echo
res="$(curl -sL "$link")"
err="$(echo "$res" | grep -io 'Page Not Found')"
if [[ ! -z "$err" ]] ; then
echo
echo "No Image Found with name => $image"
exit
else
# echo $res 2>/dev/null | jq '.results[0]|keys'
echo "tags:"
if [ $all -eq 1 ]; then
echo $res 2>/dev/null | jq '.results[] | {name: .name, size: .full_size, update_time: .last_updated}'
else
echo $res 2>/dev/null | jq '.results[] | .name'
fi
fi
echo
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment