Just suggestion and I think the answer also.
Why you want to create your own connector while there is great docker client module for java?
Consider using docker-java it is very easy to setup:
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId>
<version>3.0.3</version>
</dependency>
and configure with many different ways:
- System Environment
- System properties
- properties on class path
- programmatic
You want to create DockerClient programatically at runtime so you will need something like:
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://my-docker-host.tld:2376")
.withDockerTlsVerify(true)
.withDockerCertPath("/home/user/.docker/certs") // here is the place where your certificates are located
.withDockerConfig("/home/user/.docker")
.withApiVersion("1.23")
.withRegistryUrl("https://index.docker.io/v1/")
.withRegistryUsername("dockeruser")
.withRegistryPassword("ilovedocker")
.withRegistryEmail("dockeruser@github.com")
.build();
DockerClient docker = DockerClientBuilder.getInstance(config).build();
BTW, CertificateUtils also checks whether certificates in defined path exist and there are many great features for docker and it is already implemented.
public static boolean verifyCertificatesExist(String dockerCertPath) {
String[] files = {"ca.pem", "cert.pem", "key.pem"};
boolean result = true;
for (String file : files) {
File path = new File(dockerCertPath, file);
result &= path.exists();
}
return result;
}