检查Docker镜像在云存储库中是否存在

时间:2018-06-19 22:37:32

标签: docker dockerfile docker-build

说我有这个图像标签“ node:9.2”,如FROM node:9.2 ...

在我实际尝试docker build ...之前,是否可以使用API​​来查看是否存在带有标签“ node:9.2”的图像并且可以检索该图像?

3 个答案:

答案 0 :(得分:2)

是的

docker image pull node:9.2

答案 1 :(得分:2)

仅当图像不存在时,此脚本才会构建。

针对V2的更新

function docker_tag_exists() {
    curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null 
}

对v2使用上述功能

#!/bin/bash
function docker_tag_exists() {
    curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null 

}

if docker_tag_exists library/node 9.11.2-jessie; then
    echo "Docker image exist,...."
    echo "pulling existing docker..."
    #so docker image exist pull the docker image
    docker pull node:9.11.2-jessie
else 
    echo "Docker image not exist remotly...."
    echo "Building docker image..."
    #build docker image here with absoult or retlative path
    docker build -t nodejs .

fi

从下面的链接进行了很少的修改。 如果注册表是私有的,请检查此链接With username and password

答案 2 :(得分:2)

如果为Docker守护程序设置了"experimental": enabled,则可以使用以下命令:

泊坞清单检查节点:9.2

相关问题