@@ -441,7 +441,33 @@ public final Builder withCustomSslConfig(SSLConfig customSslConfig) {
441441 return this ;
442442 }
443443
444+ private void applyContextConfiguration (final String context ) {
445+ final Optional <DockerContextMetaFile > dockerContextMetaFile =
446+ Optional .ofNullable (context )
447+ .flatMap (ctx -> DockerContextMetaFile .resolveContextMetaFile (DockerClientConfig .getDefaultObjectMapper (),
448+ new File (this .dockerConfig ), ctx ));
449+
450+ if (dockerContextMetaFile .isPresent ()) {
451+ final Optional <DockerContextMetaFile .Endpoints .Docker > dockerEndpoint =
452+ dockerContextMetaFile .map (metaFile -> metaFile .endpoints ).map (endpoint -> endpoint .docker );
453+ if (this .dockerHost == null ) {
454+ this .dockerHost = dockerEndpoint .map (endpoint -> endpoint .host ).map (URI ::create ).orElse (null );
455+ }
456+ if (this .dockerCertPath == null ) {
457+ this .dockerCertPath = dockerContextMetaFile .map (metaFile -> metaFile .storage )
458+ .map (storage -> storage .tlsPath )
459+ .filter (file -> new File (file ).exists ()).orElse (null );
460+ if (this .dockerCertPath != null ) {
461+ this .dockerTlsVerify = dockerEndpoint .map (endpoint -> !endpoint .skipTLSVerify ).orElse (true );
462+ }
463+ }
464+ }
465+ }
466+
444467 public DefaultDockerClientConfig build () {
468+ final DockerConfigFile dockerConfigFile = readDockerConfig ();
469+ final String context = (dockerContext != null ) ? dockerContext : dockerConfigFile .getCurrentContext ();
470+ applyContextConfiguration (context );
445471
446472 SSLConfig sslConfig = null ;
447473
@@ -454,12 +480,9 @@ public DefaultDockerClientConfig build() {
454480 sslConfig = customSslConfig ;
455481 }
456482
457- final DockerConfigFile dockerConfigFile = readDockerConfig ();
458-
459- final String context = (dockerContext != null ) ? dockerContext : dockerConfigFile .getCurrentContext ();
460483 URI dockerHostUri = dockerHost != null
461484 ? dockerHost
462- : resolveDockerHost ( context );
485+ : URI . create ( SystemUtils . IS_OS_WINDOWS ? WINDOWS_DEFAULT_DOCKER_HOST : DEFAULT_DOCKER_HOST );
463486
464487 return new DefaultDockerClientConfig (dockerHostUri , dockerConfigFile , dockerConfig , apiVersion , registryUrl , registryUsername ,
465488 registryPassword , registryEmail , sslConfig );
@@ -473,14 +496,6 @@ private DockerConfigFile readDockerConfig() {
473496 }
474497 }
475498
476- private URI resolveDockerHost (String dockerContext ) {
477- return URI .create (Optional .ofNullable (dockerContext )
478- .flatMap (context -> DockerContextMetaFile .resolveContextMetaFile (
479- DockerClientConfig .getDefaultObjectMapper (), new File (dockerConfig ), context ))
480- .flatMap (DockerContextMetaFile ::host )
481- .orElse (SystemUtils .IS_OS_WINDOWS ? WINDOWS_DEFAULT_DOCKER_HOST : DEFAULT_DOCKER_HOST ));
482- }
483-
484499 private String checkDockerCertPath (String dockerCertPath ) {
485500 if (StringUtils .isEmpty (dockerCertPath )) {
486501 throw new DockerClientException (
0 commit comments