Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Listing Docker Tags on the Command Line Using a Bash Alias

blog/cards/listing-docker-tags-on-the-command-line-using-a-bash-alias.jpg

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.

Quick Jump: Demo Video Showing How to Do It

A 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 and awk 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

# ~/.aliases
dtags () {
    local image="${1}"

    wget -q https://registry.hub.docker.com/v1/repositories/"${image}"/tags -O - \
        | tr -d '[]" ' | tr '}' '\n' | awk -F: '{print $3}'
}

What interesting problems have you solved using Bash aliases and Unix pipes?

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments