How can I find a Docker image with a specific tag in Docker registry on the Docker command line? How can I find a Docker image with a specific tag in Docker registry on the Docker command line? docker docker

How can I find a Docker image with a specific tag in Docker registry on the Docker command line?


When using CoreOS, jq is available to parse JSON data.

So like you were doing before, looking at library/centos:

$ curl -s -S 'https://registry.hub.docker.com/v2/repositories/library/centos/tags/' | jq '."results"[]["name"]' |sort"6""6.7""centos5""centos5.11""centos6""centos6.6""centos6.7""centos7.0.1406""centos7.1.1503""latest"

The cleaner v2 API is available now, and that's what I'm using in the example. I will build a simple script docker_remote_tags:

#!/usr/bin/bashcurl -s -S "https://registry.hub.docker.com/v2/repositories/library/$@/tags/" | jq '."results"[]["name"]' |sort

Enables:

$ ./docker_remote_tags library/centos"6""6.7""centos5""centos5.11""centos6""centos6.6""centos6.7""centos7.0.1406""centos7.1.1503""latest"

Reference:

jq: https://stedolan.github.io/jq/ | apt-get install jq


I didn't like any of the solutions above because A) they required external libraries that I didn't have and didn't want to install. B) I didn't get all the pages.

The Docker API limits you to 100 items per request. This will loop over each "next" item and get them all (for Python it's seven pages; other may be more or less... It depends)

If you really want to spam yourself, remove | cut -d '-' -f 1 from the last line, and you will see absolutely everything.

url=https://registry.hub.docker.com/v2/repositories/library/redis/tags/?page_size=100 `# Initial url` ; \( \  while [ ! -z $url ]; do `# Keep looping until the variable url is empty` \    >&2 echo -n "." `# Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)` ; \    content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))') `# Curl the URL and pipe the output to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages) then continue to loop over the results extracting only the name; all will be stored in a variable called content` ; \    url=$(echo "$content" | head -n 1) `# Let's get the first line of content which contains the next URL for the loop to continue` ; \    echo "$content" | tail -n +2 `# Print the content without the first line (yes +2 is counter intuitive)` ; \  done; \  >&2 echo `# Finally break the line of dots` ; \) | cut -d '-' -f 1 | sort --version-sort | uniq;

Sample output:

$ url=https://registry.hub.docker.com/v2/repositories/library/redis/tags/?page_size=100 `#initial url` ; \> ( \>   while [ ! -z $url ]; do `#Keep looping until the variable url is empty` \>     >&2 echo -n "." `#Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)` ; \>     content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))') `# Curl the URL and pipe the JSON to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages) then continue to loop over the results extracting only the name; all will be store in a variable called content` ; \>     url=$(echo "$content" | head -n 1) `#Let's get the first line of content which contains the next URL for the loop to continue` ; \>     echo "$content" | tail -n +2 `#Print the content with out the first line (yes +2 is counter intuitive)` ; \>   done; \>   >&2 echo `#Finally break the line of dots` ; \> ) | cut -d '-' -f 1 | sort --version-sort | uniq;...22.62.6.172.82.8.62.8.72.8.82.8.92.8.102.8.112.8.122.8.132.8.142.8.152.8.162.8.172.8.182.8.192.8.202.8.212.8.222.8.2333.03.0.03.0.13.0.23.0.33.0.43.0.53.0.63.0.73.0.5043.23.2.03.2.13.2.23.2.33.2.43.2.53.2.63.2.73.2.83.2.93.2.103.2.113.2.10044.04.0.04.0.14.0.24.0.44.0.54.0.64.0.74.0.832bitalpinelatestnanoserverwindowsservercore

If you want the bash_profile version:

function docker-tags () {  name=$1  # Initial URL  url=https://registry.hub.docker.com/v2/repositories/library/$name/tags/?page_size=100  (    # Keep looping until the variable URL is empty    while [ ! -z $url ]; do      # Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)      >&2 echo -n "."      # Curl the URL and pipe the output to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages)      # then continue to loop over the results extracting only the name; all will be stored in a variable called content      content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))')      # Let's get the first line of content which contains the next URL for the loop to continue      url=$(echo "$content" | head -n 1)      # Print the content without the first line (yes +2 is counter intuitive)      echo "$content" | tail -n +2    done;    # Finally break the line of dots    >&2 echo  ) | cut -d '-' -f 1 | sort --version-sort | uniq;}

And simply call it: docker-tags redis

Sample output:

$ docker-tags redis...22.62.6.172.8--trunc----32bitalpinelatestnanoserverwindowsservercore


As far as I know, the CLI does not allow searching/listing tags in a repository.

But if you know which tag you want, you can pull that explicitly by adding a colon and the image name: docker pull ubuntu:saucy