docker列出镜像版本号列表

/ 0评 / 0

docker本身提供了下载指定镜像的命令,但是在命令行中无法查看版本列表,默认下载latest版本。

这对我们来说还是会有一定的困扰,如Linux下经常需要下载指定的内核版本,否则会报错"exec format error"。

解决方案

创建dockertags.sh文件

vi dockertags.sh

粘贴以下内容:

#!/bin/bash
function usage() {
        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
}



if [ $# -lt 1 ]; then
                usage
                        exit
                fi

                image="$1"
                tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O -  | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'  | awk -F: '{print $3}'`

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

使用方法:

./dockertags.sh ubuntu

注册为全局命令(可选)

mv ./dockertags.sh /usr/local/bin/dockertags.sh

就可以愉快的在任何地方查询啦,下面附查询示例:

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注