I'd like to find out if a Docker image with a specific tag exists locally. I'm fine by using a bash script if the Docker client cannot do this natively.
Just to provide some hints for a potential bash script the result of running the docker images
command returns the following:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
rabbitmq latest e8e654c05c91 5 weeks ago 143.5 MB
busybox latest 8c2e06607696 6 weeks ago 2.433 MB
rabbitmq 3.4.4 a4fbaad9f996 11 weeks ago 131.5 MB
In case you are trying to search for a docker image from a docker registry, I guess the easiest way to check if a docker image is present is by using the Docker V2 REST API Tags list service
Example:-
if the above result returns 200Ok with a list of image tags, then we know that image exists
else if you see something like
then you know for sure that image doesn't exist.
Just a bit from me to very good readers:
Build
Watch
Run
I usually test the result of
docker images -q
(as in this script):But
since.docker images
only takesREPOSITORY
as parameter, you would need to grep on tag, without using-q
docker images
takes tags now (docker 1.8+)[REPOSITORY[:TAG]]
The other approach mentioned below is to use docker inspect.
But with docker 17+, the syntax for images is:
docker image inspect
(on an non-existent image, the exit status will be non-0)Using
test
or in one line
You can use like the following:
Or:
Try
docker inspect
, for example:But now with an image that exists, you'll get a bunch of information, eg:
And it's in a nice json format.