diff --git a/core/src/main/java/org/testcontainers/dockerclient/DockerMachineClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/DockerMachineClientProviderStrategy.java index 4846d4e7ddf..59211e317a2 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/DockerMachineClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/DockerMachineClientProviderStrategy.java @@ -14,6 +14,9 @@ * Use Docker machine (if available on the PATH) to locate a Docker environment. */ public class DockerMachineClientProviderStrategy extends DockerClientProviderStrategy { + private static final String PING_TIMEOUT_DEFAULT = "30"; + private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.dockermachineprovider.timeout"; + @Override public void test() throws InvalidConfigurationException { @@ -44,7 +47,8 @@ public void test() throws InvalidConfigurationException { } // If the docker-machine VM has started, the docker daemon may still not be ready. Retry pinging until it works. - ping(client, 30); + final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); + ping(client, timeout); } @Override diff --git a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java index ec1b7f2ab91..4b414b70d5e 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java @@ -8,6 +8,8 @@ * to try and locate a docker environment. */ public class EnvironmentAndSystemPropertyClientProviderStrategy extends DockerClientProviderStrategy { + private static final String PING_TIMEOUT_DEFAULT = "10"; + private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.environmentprovider.timeout"; @Override public void test() throws InvalidConfigurationException { @@ -17,8 +19,10 @@ public void test() throws InvalidConfigurationException { config = DefaultDockerClientConfig.createDefaultConfigBuilder().build(); client = getClientForConfig(config); - ping(client, 1); + final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); + ping(client, timeout); } catch (Exception e) { + LOGGER.error("ping failed with configuration {} due to {}", getDescription(), e.toString(), e); throw new InvalidConfigurationException("ping failed"); } diff --git a/core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java index b13d5a633ec..99f5153f35b 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java @@ -10,10 +10,12 @@ import java.nio.file.Paths; public class UnixSocketClientProviderStrategy extends DockerClientProviderStrategy { - protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock"; private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH; private static final int SOCKET_FILE_MODE_MASK = 0xc000; + private static final String PING_TIMEOUT_DEFAULT = "10"; + private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.unixsocketprovider.timeout"; + @Override public void test() @@ -52,7 +54,8 @@ protected DockerClientConfig tryConfiguration(String dockerHost) { .build(); client = getClientForConfig(config); - ping(client, 10); + final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT)); + ping(client, timeout); return config; }