查看Docker镜像仓库中镜像的所有标签

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kongxx/article/details/86558328

用 Docker 的人都知道,我们在查询远端镜像仓库中镜像的时候,在命令行只能看到镜像名,说明等信息,而看不到标签。因此,如果我想要查看镜像有哪些标签,就只能通过网页的方式查看,比如通过 https://hub.docker.com/ 查看,这样实在是太麻烦,于是乎,我想是不是可以写个小工具来干这个事呢?答案当然是肯定的。下面就看看怎样实现的吧。

写了个脚本 list_img_tags.sh,内容如下:

#!/bin/sh

repo_url=https://registry.hub.docker.com/v1/repositories
image_name=$1

curl -s ${repo_url}/${image_name}/tags | json_reformat | grep name | awk '{print $2}' | sed -e 's/"//g'

其实,实现方法就是通过镜像仓库的 restful API,来查询,然后把返回的 json 结果简单处理一下,然后打印出来。

上面脚本的实现是只从 hub.docker.com 来查询,如果使用其它仓库,可以根据需要修改仓库的url。

测试一哈

$ ./list_img_tags.sh tensorflow/tensorflow
latest
0.10.0
0.10.0-devel
0.10.0-devel-gpu
0.10.0-gpu
0.10.0rc0
0.10.0rc0-devel
0.10.0rc0-devel-gpu
0.10.0rc0-gpu
0.11.0
...

猜你喜欢

转载自blog.csdn.net/kongxx/article/details/86558328
今日推荐