From 204821e226b46021bcd312093a9c72fcf3d87289 Mon Sep 17 00:00:00 2001 From: Ermin Hrkalovic <160042555+swermin@users.noreply.github.com> Date: Sat, 3 Oct 2026 23:01:19 +0200 Subject: [PATCH 1/3] add option to use dockerContext as configuration --- ...tAndSystemPropertyClientProviderStrategy.java | 3 +++ ...SystemPropertyClientProviderStrategyTest.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java index 969610373d1..b220e0bbc1e 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java @@ -50,6 +50,9 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() { case "autoIgnoringUserProperties": applicable = configBuilder.isDockerHostSetExplicitly(); break; + case "dockerContext": + applicable = true; + break; default: throw new InvalidConfigurationException("Invalid value for dockerconfig.source: " + dockerConfigSource); } diff --git a/core/src/test/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategyTest.java b/core/src/test/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategyTest.java index be4dcd446a8..301a618d75c 100644 --- a/core/src/test/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategyTest.java +++ b/core/src/test/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategyTest.java @@ -154,4 +154,20 @@ void notApplicableWhenIgnoringUserPropertiesAndNotConfigured() { assertThat(strategy.isApplicable()).isFalse(); } + + @Test + void applicableWhenUsingDockerContext() { + Mockito + .doReturn("dockerContext") + .when(TestcontainersConfiguration.getInstance()) + .getEnvVarOrProperty(eq("dockerconfig.source"), anyString()); + + Properties oldProperties = System.getProperties(); + try { + EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy(); + assertThat(strategy.isApplicable()).isTrue(); + } finally { + System.setProperties(oldProperties); + } + } } From e78538f205961a163a94be6c4e9fc6a08df208e3 Mon Sep 17 00:00:00 2001 From: Ermin Hrkalovic <160042555+swermin@users.noreply.github.com> Date: Sat, 3 Oct 2026 23:01:32 +0200 Subject: [PATCH 2/3] add docs to specify that dockerContext can be used --- docs/features/configuration.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/features/configuration.md b/docs/features/configuration.md index 389936cb89f..b8bf62a9e28 100644 --- a/docs/features/configuration.md +++ b/docs/features/configuration.md @@ -132,3 +132,11 @@ In addition, you can deactivate this behaviour by specifying: ```properties dockerconfig.source=autoIgnoringUserProperties # 'auto' by default ``` + +## Docker Context support + +For users who wants to use docker context for host configuration can set the following property: +```properties +dockerconfig.source=dockerContext # 'auto' by default +``` +Warning, this option will not do any extra checks, it defaults to whatever is configured through docker and/or docker context From f3bc6b3a527666a56077c5b9b3cf22022efa1cb9 Mon Sep 17 00:00:00 2001 From: Ermin Hrkalovic <160042555+swermin@users.noreply.github.com> Date: Sat, 3 Oct 2026 23:01:35 +0200 Subject: [PATCH 3/3] add comments to explain that the dockerContext option relies on docker-java default config --- .../EnvironmentAndSystemPropertyClientProviderStrategy.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java index b220e0bbc1e..a84746adbda 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java @@ -51,6 +51,8 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() { applicable = configBuilder.isDockerHostSetExplicitly(); break; case "dockerContext": + // none of the Testcontainers configuration are relevant when using docker contexts since we rely + // on the docker-java default to have all the necessary configuration already set. applicable = true; break; default: