From 48ceb3c844cbe77ebcf78ac4b43eb5dddc02f8b7 Mon Sep 17 00:00:00 2001 From: Matthieu Laloup Date: Thu, 20 Jun 2019 14:58:07 +0200 Subject: [PATCH] Fix proposal for non resolved issue https://github.com/spotify/dockerfile-maven/issues/112 --- .../plugin/dockerfile/AbstractDockerMojo.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java b/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java index 74ada869..58a55083 100644 --- a/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java +++ b/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java @@ -41,6 +41,8 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; + +import org.apache.commons.lang3.StringUtils; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.execution.MavenSession; @@ -147,6 +149,13 @@ public String getFileName() { @Parameter(property = "dockerfile.password") protected String password; + /** + * URI used for executing docker commands. For example "http://localhost:2375" + * If this is set, the DOCKER_HOST environment variable will be ignored. + */ + @Parameter(property = "dockerfile.dockerHostUri") + protected String dockerHostUri; + /** * Whether to output a verbose log when performing various operations. */ @@ -435,12 +444,15 @@ private DockerClient openDockerClient() throws MojoExecutionException { final RegistryAuthSupplier authSupplier = createRegistryAuthSupplier(); try { - return DefaultDockerClient.fromEnv() - .readTimeoutMillis(readTimeoutMillis) - .connectTimeoutMillis(connectTimeoutMillis) - .registryAuthSupplier(authSupplier) - .useProxy(useProxy) - .build(); + DefaultDockerClient.Builder builder = DefaultDockerClient.fromEnv(); + if (StringUtils.isNotEmpty(dockerHostUri)) { + builder.uri(dockerHostUri); + } + return builder.readTimeoutMillis(readTimeoutMillis) + .connectTimeoutMillis(connectTimeoutMillis) + .registryAuthSupplier(authSupplier) + .useProxy(useProxy) + .build(); } catch (DockerCertificateException e) { throw new MojoExecutionException("Could not load Docker certificates", e); }