Skip to content

Images API

Mihai edited this page Apr 20, 2020 · 7 revisions

Images API:

final Docker docker = ...;
final Images images = docker.images();

Pull an Image

This will pull an image, from the Registry, to the Docker Engine.

final Image helloWorld = images.pull("hello-world", "latest");

Import an Image

This will import an Image, from the given URL and Repo, to the Docker Engine

final Image imported = images.import(
    new URL("http://example.com/exampleimage.tgz"),
    "hello-world"
);

Iterate Over Images

Images implements Iterable<Image>. To iterate over all images in the Docke Engine (no filters applied), just use:

for(final Image img : images) {
//...
}

Work With An Image

An Image represents the Image JSON resource in Docker as well as the API endpoints performing on this resource. Image implements javax.json.JsonObject and holds the JSON representation accurate at the moment of its instantiation.

Once you have an Image, here's what you can do with it:

final Image image = ...;
final Container running = image.run();           //run a Container from it.
final JsonObject inspection = image.inspect();   //get the latest JSON inspection
final Iterable<Image> history = image.history(); //get its History
image.tag("repo", "name");                       //tag the Image
image.delete();                                  //delete it
...

Import Images from Tar File

This call will upload the read images to the Docker engine and return all of them (pre-existing and imported) back.

final Images fromTar = images.importFromTar("/path/images.tar");

Delete (prune) Unused Images

This call will delete all the unused images from the Docker Engine.

images.prune();

Filter Images

You can filter them by providing a Map of filters as explained in the API Guide:

final Images filtered = images.filter(...);

Get Parent Docker

Get the Docker instance to which the Images belong:

final Docker parent = images.docker();