Init Docker API
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
27c6fd5888
commit
8b1d592143
51
src/main/java/net/libertacasa/pubsh/web/Docker.java
Normal file
51
src/main/java/net/libertacasa/pubsh/web/Docker.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package net.libertacasa.pubsh.web;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.model.Image;
|
||||||
|
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||||
|
import com.github.dockerjava.core.DockerClientConfig;
|
||||||
|
import com.github.dockerjava.core.DockerClientImpl;
|
||||||
|
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
|
||||||
|
import com.github.dockerjava.transport.DockerHttpClient;
|
||||||
|
|
||||||
|
public class Docker {
|
||||||
|
|
||||||
|
static DockerClientConfig DockerConfig = DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||||
|
.withDockerHost("tcp://sweetsuse:2375")
|
||||||
|
.withDockerTlsVerify(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
static DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
|
||||||
|
.dockerHost(DockerConfig.getDockerHost())
|
||||||
|
.sslConfig(DockerConfig.getSSLConfig())
|
||||||
|
.maxConnections(100)
|
||||||
|
.connectionTimeout(Duration.ofSeconds(30))
|
||||||
|
.responseTimeout(Duration.ofSeconds(45))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
static DockerClient dockerClient = DockerClientImpl.getInstance(DockerConfig, httpClient);
|
||||||
|
|
||||||
|
public static List<String> getImageChecksums() {
|
||||||
|
List<Image> imageQuery;
|
||||||
|
List<String> imageList;
|
||||||
|
imageQuery = dockerClient.listImagesCmd().exec();
|
||||||
|
imageList = imageQuery.stream().map(Image::getId).collect(Collectors.toList());
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Image> getImages() {
|
||||||
|
List<Image> imageQuery;
|
||||||
|
imageQuery = dockerClient.listImagesCmd().exec();
|
||||||
|
return imageQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<com.github.dockerjava.api.model.Container> getContainers() {
|
||||||
|
List<com.github.dockerjava.api.model.Container> containerQuery;
|
||||||
|
containerQuery = dockerClient.listContainersCmd().withShowAll(true).exec();
|
||||||
|
return containerQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user