I am using the docker-java Maven library, and I would like to know if there is a way to check if an image has already been pulled or is present locally before pulling it if necessary, with only the image name. Currently, I have to pull the image everytime I execute it to ensure it is present locally, which is not nice.
If you need to do it in Java, you can use the inspectImageCmd
method of the com.github.dockerjava.api.DockerClient
interface. Then check the returned InspectImageResponse
response object. Something like this:
String imageId = ...;
InspectImageResponse response = dockerClient.inspectImageCmd(imageid).exec();
docker-java
is just a wrapper for the Docker REST API and the inspect command is the equivalent of the GET
http request to /images/{imageid}/json
. See section 3.2 Images in Docker Engine API.