Listing Docker Tags on the Command Line Using a Bash Alias
In this short video we'll go over how to list all Docker tags for a specific image on the Docker Hub using the command line.
A new version of this video is available
Docker deprecated their v1 API in September 2022 so I made an updated video.
Check It OutA while ago I wrote Docker tip #81 which went over searching the Docker Hub on the command line and that tip also included listing Docker tags with a Bash alias.
This video uses the same alias but instead of just providing the code, we’re going to focus on going over how the alias works. By the end of the video you’ll see how to use Bash aliases and piping Unix commands together to solve other types of problems you may run into.
# Demo Video Showing How to Do It
Timestamped Table of Contents
- 0:39 – Piping the output of the alias to fzf or grep
- 1:17 – Looking at my
~/.aliases
file from my dotfiles - 1:59 – Including a separate Bash alias file into your
~/.bashrc
file - 2:42 – Passing arguments into a Bash function
- 3:19 – Piping together
wget
,tr
andawk
to get a list of Docker tags for an image - 3:36 – Using
wget
to get our data back from the Docker Hub and writing it to stdout - 4:48 – Using
tr
to delete characters that we don’t want from the output - 6:04 – Using
tr
again to replace a single character with a new line - 7:09 – Using
awk
to parse a string based on a specific delimiter character - 8:54 – Taking advantage of Unix pipes to solve all sorts of problems quickly
Code snippets
In September 2022 Docker deprecated v1 of their API. Here’s the revised alias that’s using v2 of their API. This no longer matches the above video but it works:
# Working v2 API solution:
dtags () {
local image="${1}"
curl --silent \
"https://registry.hub.docker.com/v2/repositories/library/${image}/tags?page_size=1000" \
| jq -r ".results[].name" | sort --version-sort
}
# Original deprecated v1 API solution (I'm keeping this here for historic purposes):
dtags () {
local image="${1}"
curl --silent https://registry.hub.docker.com/v1/repositories/"${image}"/tags \
| tr -d '[]" ' | tr '}' '\n' | awk -F: '{print $3}' | sort --version-sort
}
Reference Links
What interesting problems have you solved using Bash aliases and Unix pipes?