列出 USTC Docker 镜像的标签

2020-02-28

This article is a bit old and the content may be outdated, so please refer to it with caution and remember to check the latest official materials (such as documentation, etc.)

不再为网络条件发愁!

众所周知,如果网络条件好的话,可以使用官方的 API 获取镜像标签列表。

如 v2 接口:

#!/bin/bash
i = 0

while [ $? == 0 ]
do
   i = $(( i + 1 ))
   curl https://registry.hub.docker.com/v2/repositories/library/nginx/tags/?page=$i | jq '."results"[]["name"]'

done
bash

但是天朝。。

网易和阿里的官方 API 里都要求有 API Key 签名认证之类,比较繁琐

故先尝试使用 USTC 的镜像,缺点是速度慢、标签不全。。根据一波猜测,得到了 USTC 标签的 API:

https://docker.mirrors.ustc.edu.cn/v2/library/nginx/tags/list
text

同理又意外获得了网易的,标签全!

https://hub-mirror.c.163.com/v2/library/nginx/tags/list
text

于是根据 https://stackoverflow.com/a/39454426/8810271 代码改编:

#!/bin/bash

if [ $# -lt 1 ]
then
cat << HELP

dockertags  --  list all tags for a Docker image on a remote registry.

EXAMPLE:
    - list all tags for ubuntu:
       dockertags ubuntu

    - list all php tags containing apache:
       dockertags php apache

HELP
exit
fi

image = "$1"
tags = `curl https://hub-mirror.c.163.com/v2/library/${image}/tags/list | sed -e 's/.*\[//g' -e 's/"//g' -e 's/\]\}$//g' -e 's/,/\n/g'`

if [ -n "$2" ]
then
    tags = ` echo "${tags}" | grep "$2" `
fi

echo "${tags}"
bash
Leave your comments and reactions on GitHub