Reputation: 17342
I'm creating a new tag from an existing image. But sometimes the image is missing, and the command fails. So I need to check if an docker image is existing at all before running the command:
$ docker tag source:anything target:something
But how do I check for existing docker image and how do I use an if-statement correctly in the terminal?
if [docker source:anything] docker tag source:anything target:something fi
Upvotes: 0
Views: 182
Reputation: 3135
this is the correct way to do it
if [[ "$(docker images -q myimage:mytag 2> /dev/null)" == "" ]]; then
// do something
fi
you could also use
[ ! -z $(docker images -q myimage:mytag) ] || echo "does not exist"
Upvotes: 1