diff --git a/src/main/java/com/github/dockerjava/core/DockerClientConfig.java b/src/main/java/com/github/dockerjava/core/DockerClientConfig.java index a03d6e086..31cfc0c58 100644 --- a/src/main/java/com/github/dockerjava/core/DockerClientConfig.java +++ b/src/main/java/com/github/dockerjava/core/DockerClientConfig.java @@ -109,14 +109,16 @@ private String checkDockerCertPath(boolean dockerTlsVerify, String dockerCertPat if (!certPath.exists()) { throw new DockerClientException( - "Certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + "' doesn't exist."); + "Enabled TLS verification (DOCKER_TLS_VERIFY=1) but certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + + "' doesn't exist."); } if (certPath.isDirectory()) { return dockerCertPath; } else { throw new DockerClientException( - "Certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + "' doesn't point to a directory."); + "Enabled TLS verification (DOCKER_TLS_VERIFY=1) but certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + + "' doesn't point to a directory."); } } } else { @@ -375,7 +377,6 @@ public final DockerClientConfigBuilder withDockerHost(String dockerHost) { return this; } - public final DockerClientConfigBuilder withApiVersion(RemoteApiVersion apiVersion) { this.apiVersion = apiVersion.getVersion(); return this; @@ -417,8 +418,12 @@ public final DockerClientConfigBuilder withDockerConfig(String dockerConfig) { } public final DockerClientConfigBuilder withDockerTlsVerify(String dockerTlsVerify) { - String trimmed = dockerTlsVerify.trim(); - this.dockerTlsVerify = "true".equalsIgnoreCase(trimmed) || "1".equals(trimmed); + if (dockerTlsVerify != null) { + String trimmed = dockerTlsVerify.trim(); + this.dockerTlsVerify = "true".equalsIgnoreCase(trimmed) || "1".equals(trimmed); + } else { + this.dockerTlsVerify = false; + } return this; } @@ -433,4 +438,3 @@ public DockerClientConfig build() { } } } - diff --git a/src/main/resources/META-INF/services/com.github.dockerjava.api.command.DockerCmdExecFactory b/src/main/resources/META-INF/services/com.github.dockerjava.api.command.DockerCmdExecFactory deleted file mode 100644 index f0686bc9f..000000000 --- a/src/main/resources/META-INF/services/com.github.dockerjava.api.command.DockerCmdExecFactory +++ /dev/null @@ -1 +0,0 @@ -com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl \ No newline at end of file diff --git a/src/main/resources/docker-java.properties b/src/main/resources/docker-java.properties index ea85f6c01..fc9209c97 100644 --- a/src/main/resources/docker-java.properties +++ b/src/main/resources/docker-java.properties @@ -1,13 +1,7 @@ -#docker.io.url=https://localhost:2376 -#docker.io.dockerCertPath=${user.home}/.docker -#docker.io.dockerCfgPath=${user.home}/.dockercfg -#docker.io.username=${user.name} -#docker.io.serverAddress=https://index.docker.io/v1/ -# -DOCKER_HOST=tcp://localhost:2376 -DOCKER_TLS_VERIFY=1 +DOCKER_HOST=unix:///var/run/docker.sock DOCKER_CONFIG=${user.home}/.docker -DOCKER_CERT_PATH=${user.home}/.docker/certs +#DOCKER_TLS_VERIFY=1 +#DOCKER_CERT_PATH=${user.home}/.docker/certs api.version= registry.url=https://index.docker.io/v1/ diff --git a/src/test/java/com/github/dockerjava/core/DockerClientConfigTest.java b/src/test/java/com/github/dockerjava/core/DockerClientConfigTest.java index a363e12ec..ee679a0af 100644 --- a/src/test/java/com/github/dockerjava/core/DockerClientConfigTest.java +++ b/src/test/java/com/github/dockerjava/core/DockerClientConfigTest.java @@ -4,8 +4,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.core.Is.is; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertNull; import java.lang.reflect.Field; import java.net.URI; @@ -54,8 +53,6 @@ public void environmentDockerHost() throws Exception { // and it looks to be SSL disabled env.remove("DOCKER_CERT_PATH"); - - // given default cert path Properties systemProperties = new Properties(); systemProperties.setProperty("user.name", "someUserName"); @@ -82,7 +79,6 @@ public void environment() throws Exception { env.put(DockerClientConfig.DOCKER_CERT_PATH, dockerCertPath()); env.put(DockerClientConfig.DOCKER_TLS_VERIFY, "1"); - // when you build a config DockerClientConfig config = buildConfig(env, new Properties()); @@ -106,12 +102,12 @@ public void defaults() throws Exception { DockerClientConfig config = buildConfig(Collections. emptyMap(), systemProperties); // then the cert path is as expected - assertEquals(config.getDockerHost(), URI.create("tcp://localhost:2376")); + assertEquals(config.getDockerHost(), URI.create("unix:///var/run/docker.sock")); assertEquals(config.getRegistryUsername(), "someUserName"); assertEquals(config.getRegistryUrl(), AuthConfig.DEFAULT_SERVER_ADDRESS); assertEquals(config.getApiVersion(), RemoteApiVersion.unknown()); assertEquals(config.getDockerConfig(), homeDir() + "/.docker"); - assertEquals(config.getDockerCertPath(), homeDir() + "/.docker/certs"); + assertNull(config.getDockerCertPath()); } @Test