I have imported docker-java client library.
Using above library how can I get all containers/images available?
Sample code will help a lot.
Able to get containers/images using docker-java client library.
To get all the images
DockerClient dockerClient = DockerClientBuilder.getInstance("http://localhost:2375").build();
List<Image> images = dockerClient.listImagesCmd().exec();
for(int i=0; i < images.size(); i++){
System.out.println(images.get(i));
}
To get all the containers
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.command.ListImagesCmd;
import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DockerClientBuilder;
String localDockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";
DockerClient dockerClient = DockerClientBuilder.getInstance(localDockerHost).build();
List<Container> containers = dockerClient.listContainersCmd().exec();
for(int i=0; i < containers.size(); i++){
System.out.println(containers.get(i));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With