Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 56
Containers API
finalDockerdocker = ...;
finalContainerscontainers = docker.containers();- Iterate Running Containers
- Iterate All Containers
- Multiple Create Methods
- Work With A Container
- Filter Containers
You can iterate over all of the running containers like this:
for(finalContainerrunning : containers) {
//...
}You can iterate over all containers like this:
for(finalContainerrunning : containers.all()) {
//...
}You can create a Container by giving it the image's String name or by giving it a whole JsonObject config object while specifying a name for it or not.
finalContainerc1 = containers.create("hello-world")
finalContainerc2 = containers.create("containerName", "hello-world")
finalContainerc3 = containers.create(JsonObject)
finalContainerc4 = containers.create("containerName", JsonObject)Of course, if you need a running Container, a more elegant solution is to use the Images API to pull an Image and run the container from it:
finalImageimg = ...;
finalContainercontainer = img.run();A Container represents the Container JSON resource in Docker as well as the API endpoints performing on this resource. Container implements javax.json.JsonObject and holds the JSON representation accurate at the moment of its instantiation.
Once you have an Container, here's what you can do with it:
finalContainercontainer = ...;
finalJsonObjectinspection = container.inspect();
finalLogslogs = container.logs();
container.start();
container.stop(); container.kill();
container.restart();
container.rename("newName");
container.pause();
container.unpause();
container.waitOn("not-running"|"next-exit"|"removed");
container.remove();
...You can use the filter(Map) method to filter the Containers:
finalContainersoriginal = docker.containers;
finalContainersfiltered = original.filter(...);//multiple calls to filter will use all specified filters.for(finalContainerctn : filtered.all()) {
//filtered containers here
}