66import com .github .dockerjava .core .NameParser .HostnameReposName ;
77import com .github .dockerjava .core .NameParser .ReposTag ;
88import org .apache .commons .lang .StringUtils ;
9+ import org .apache .commons .lang .SystemUtils ;
910import org .apache .commons .lang .builder .EqualsBuilder ;
1011import org .apache .commons .lang .builder .HashCodeBuilder ;
1112import org .apache .commons .lang .builder .ToStringBuilder ;
@@ -58,6 +59,10 @@ public class DefaultDockerClientConfig implements Serializable, DockerClientConf
5859
5960 static final Properties DEFAULT_PROPERTIES = new Properties ();
6061
62+ static final String DEFAULT_DOCKER_HOST = "unix:///var/run/docker.sock" ;
63+
64+ static final String WINDOWS_DEFAULT_DOCKER_HOST = "npipe:////./pipe/docker_engine" ;
65+
6166 static {
6267 CONFIG_KEYS .add (DOCKER_HOST );
6368 CONFIG_KEYS .add (DOCKER_TLS_VERIFY );
@@ -69,7 +74,6 @@ public class DefaultDockerClientConfig implements Serializable, DockerClientConf
6974 CONFIG_KEYS .add (REGISTRY_EMAIL );
7075 CONFIG_KEYS .add (REGISTRY_URL );
7176
72- DEFAULT_PROPERTIES .put (DOCKER_HOST , "unix:///var/run/docker.sock" );
7377 DEFAULT_PROPERTIES .put (DOCKER_CONFIG , "${user.home}/.docker" );
7478 DEFAULT_PROPERTIES .put (REGISTRY_URL , "https://index.docker.io/v1/" );
7579 DEFAULT_PROPERTIES .put (REGISTRY_USERNAME , "${user.name}" );
@@ -337,8 +341,12 @@ public static class Builder {
337341 * registry.email, DOCKER_CERT_PATH, and DOCKER_CONFIG.
338342 */
339343 public Builder withProperties (Properties p ) {
340- return withDockerHost (p .getProperty (DOCKER_HOST ))
341- .withDockerTlsVerify (p .getProperty (DOCKER_TLS_VERIFY ))
344+
345+ if (p .getProperty (DOCKER_HOST ) != null ) {
346+ withDockerHost (p .getProperty (DOCKER_HOST ));
347+ }
348+
349+ return withDockerTlsVerify (p .getProperty (DOCKER_TLS_VERIFY ))
342350 .withDockerConfig (p .getProperty (DOCKER_CONFIG ))
343351 .withDockerCertPath (p .getProperty (DOCKER_CERT_PATH ))
344352 .withApiVersion (p .getProperty (API_VERSION ))
@@ -412,6 +420,10 @@ public final Builder withDockerTlsVerify(Boolean dockerTlsVerify) {
412420 return this ;
413421 }
414422
423+ public final boolean isDockerHostSetExplicitly () {
424+ return dockerHost != null ;
425+ }
426+
415427 /**
416428 * Overrides the default {@link SSLConfig} that is used when calling {@link Builder#withDockerTlsVerify(java.lang.Boolean)} and
417429 * {@link Builder#withDockerCertPath(String)}. This way it is possible to pass a custom {@link SSLConfig} to the resulting
@@ -435,7 +447,11 @@ public DefaultDockerClientConfig build() {
435447 sslConfig = customSslConfig ;
436448 }
437449
438- return new DefaultDockerClientConfig (dockerHost , dockerConfig , apiVersion , registryUrl , registryUsername ,
450+ URI dockerHostUri = dockerHost != null
451+ ? dockerHost
452+ : URI .create (SystemUtils .IS_OS_WINDOWS ? WINDOWS_DEFAULT_DOCKER_HOST : DEFAULT_DOCKER_HOST );
453+
454+ return new DefaultDockerClientConfig (dockerHostUri , dockerConfig , apiVersion , registryUrl , registryUsername ,
439455 registryPassword , registryEmail , sslConfig );
440456 }
441457
0 commit comments