Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

列出 USTC Docker 镜像的标签 #75

Open
AllanChain opened this issue Feb 28, 2020 · 0 comments
Open

列出 USTC Docker 镜像的标签 #75

AllanChain opened this issue Feb 28, 2020 · 0 comments
Labels
blog: programming @post This is a blog post tag: docker |108685840-96de5d00-752f-11eb-91df-f5e884d827bf.png

Comments

@AllanChain
Copy link
Owner

AllanChain commented Feb 28, 2020

View Post on Blog

This post was originally created at 2020-02-28T21:38:39+08:00

不再为网络条件发愁!


众所周知,如果网络条件好的话,可以使用官方的 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

但是天朝。。

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

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

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

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

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

于是根据 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}"
@AllanChain AllanChain added blog: programming tag: docker |108685840-96de5d00-752f-11eb-91df-f5e884d827bf.png and removed Gitalk labels May 25, 2020
@AllanChain AllanChain changed the title List Docker Tags USTC | AC's Blog List Docker Tags USTC May 25, 2020
@AllanChain AllanChain changed the title List Docker Tags USTC 列出 USTC Docker 镜像的标签 May 25, 2020
@AllanChain AllanChain added the @post This is a blog post label Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog: programming @post This is a blog post tag: docker |108685840-96de5d00-752f-11eb-91df-f5e884d827bf.png
Projects
None yet
Development

No branches or pull requests

1 participant