Skip to content

Instantly share code, notes, and snippets.

@jdewinne
Last active September 12, 2018 23:47
Show Gist options
  • Save jdewinne/3f13494858fad8b6b2b88ebd3439f1ea to your computer and use it in GitHub Desktop.
Save jdewinne/3f13494858fad8b6b2b88ebd3439f1ea to your computer and use it in GitHub Desktop.
dockertags
#!/bin/bash
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image on a remote registry.
EXAMPLE:
- list all tags for ubuntu:
dockertags -i ubuntu
- list all php tags containing apache (regular expression should be working):
dockertags -c apache -i php
- list all frolvlad/alpine-glibc tags excluding 3.2 (regular expression should be working)
dockertags -e 3.2 -i frolvlad/alpine-glibc
HELP
fi
while getopts ":i:c:e:" opt; do
case $opt in
i) image="$OPTARG"
;;
c) contains="$OPTARG"
;;
e) excludes="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
if [ -n "${contains}" ]
then
tags=` echo "${tags}" | grep -E "${contains}" `
fi
if [ -n "${excludes}" ]
then
tags=` echo "${tags}" | grep -E -v "${excludes}" `
fi
echo "${tags}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment