Say I have this image tag "node:9.2" as in FROM node:9.2...
is there an API I can hit to see if image with tag "node:9.2" exists and can be retrieved, before I actually try docker build ...?
This script will build only if image not exist.
update for V2
function docker_tag_exists() {
    curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null 
}
Use above function for 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 little modification from the link below. If the registry is private u check this link With username and password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With