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 →

Docker Tip #81: Searching the Docker Hub on the Command Line


If you're looking for an image or its tags from the Docker Hub, you can search and filter them using the Docker CLI tool.

If you’re new’ish to Docker, you’ll often find yourself browsing the Docker Hub looking to see if any images exist to solve your problem (preferably official images).

There’s nothing wrong with that, but you can also do this from the comfort of the command line without resorting to a terminal based browser like Lynx.

Search for an image with the Docker CLI:
docker search python

That will return back:

NAME            DESCRIPTION                                       STARS   OFFICIAL   AUTOMATED
python          Python is an interpreted, interactive, objec...   4029    [OK]
django          Django is a free web application framework, ...   806     [OK]
pypy            PyPy is a fast, compliant alternative implem...   175     [OK]
kaggle/python   Docker image for Python scripts run on Kaggle     114                [OK]

+ 21 other results (ordered by stars)

You can even type in something like docker search pyt if you only know part of the name.

Limiting it to official images only:
docker search ruby --filter="is-official=true"

That will return back:

NAME      DESCRIPTION                                       STARS   OFFICIAL   AUTOMATED
ruby      Ruby is a dynamic, reflective, object-orient...   1643    [OK]
redmine   Redmine is a flexible project management web...   716     [OK]
jruby     JRuby (http://www.jruby.org) is an implement...   82      [OK]

I’ve been using Docker for almost 5 years and I only learned that this existed today.

Although, having the image name alone isn’t too useful, you can also get a list of tags for each image. Unfortunately this isn’t built into the docker search command but you can do it with a little bit of shell scripting.

Bash function / alias to get a list of Docker image tags:
dtags () {
    local image="${1}"

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

Now you can run dtags debian to get a full list of Debian tags or any image you want! If you’re curious, you can find my dotfiles on GitHub which has this function and many more Docker related aliases set up.

There’s also this video tutorial that explains the alias in more detail.

Free Intro to Docker Email Course

Over 5 days you'll get 1 email per day that includes video and text from the premium Dive Into Docker course. By the end of the 5 days you'll have hands on experience using Docker to serve a website.