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

Ale*_*lls 5 docker dockerfile docker-build

假设我有这个图像标签“节点:9.2”,如FROM node:9.2...

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

Adi*_*iii 7

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

V2 更新

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

将上述函数用于 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
Run Code Online (Sandbox Code Playgroud)

从下面的链接几乎没有修改。如果注册表是私有的,请使用用户名和密码检查此链接


emo*_*ory -10

是的。

docker image pull node:9.2
Run Code Online (Sandbox Code Playgroud)