Skip to content

Instantly share code, notes, and snippets.

@ashirazi2
Last active August 25, 2023 13:58
Show Gist options
  • Select an option

  • Save ashirazi2/df91dd53063cb24188a438f6e95632d1 to your computer and use it in GitHub Desktop.

Select an option

Save ashirazi2/df91dd53063cb24188a438f6e95632d1 to your computer and use it in GitHub Desktop.
List all tags for a Docker image
# Add this function somewhere useful like ~/.bash_login or ~/.zlogin
docker-tags() {
if [ -z "$@" ]; then
echo "usage: docker-tags org/repo" >&2
else
TOKEN="$(security find-generic-password -a "$USER" -s dockerhub-token -w)"
if [ -z "$TOKEN" ]; then
echo "ensure MacOS keychain has: name: dockerhub-token acct: $USER" >&2
else
if ! grep -q / <<< "$@"; then
ns_repo="library/$@"
else
ns_repo="$@"
fi
AUTH="Authorization: JWT $TOKEN"
TAGS_API="https://hub.docker.com/v2/repositories/$ns_repo/tags"
current_page="${TAGS_API}?page_size=100"
while [ "$current_page" != null ]; do
curl -sH "$AUTH" "$current_page" | jq ".results[].name" | tr -d '"'
current_page=$(curl -sH "$AUTH" "$current_page" | jq ".next" | tr -d '"')
done
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment