diff --git a/core/pom.xml b/core/pom.xml index 5cdef3955fc..05f0c0d2214 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -204,11 +204,13 @@ package - - + + - + tofile="${project.build.directory}/exploded/META-INF/native/liborg-testcontainers-shaded-netty-transport-native-epoll.so"/> + diff --git a/core/src/main/java/org/testcontainers/DockerClientFactory.java b/core/src/main/java/org/testcontainers/DockerClientFactory.java index 2bfaa9113c2..5333abe2858 100644 --- a/core/src/main/java/org/testcontainers/DockerClientFactory.java +++ b/core/src/main/java/org/testcontainers/DockerClientFactory.java @@ -70,22 +70,14 @@ public synchronized static DockerClientFactory instance() { * * @return a new initialized Docker client */ - public DockerClient client() { - return client(true); - } - - /** - * - * @param failFast fail if client fails to ping Docker daemon - * @return a new initialized Docker client - */ @Synchronized - public DockerClient client(boolean failFast) { + public DockerClient client() { - if (strategy == null) { - strategy = DockerClientProviderStrategy.getFirstValidStrategy(CONFIGURATION_STRATEGIES); + if (strategy != null) { + return strategy.getClient(); } + strategy = DockerClientProviderStrategy.getFirstValidStrategy(CONFIGURATION_STRATEGIES); DockerClient client = strategy.getClient(); if (!preconditionsChecked) { @@ -104,11 +96,6 @@ public DockerClient client(boolean failFast) { preconditionsChecked = true; } - if (failFast) { - // Ping, to fail fast if our docker environment has gone away - client.pingCmd().exec(); - } - return client; } @@ -197,7 +184,7 @@ private void checkDiskSpace(DockerClient client) { */ public String getActiveApiVersion() { if (!preconditionsChecked) { - client(true); + client(); } return activeApiVersion; } @@ -207,7 +194,7 @@ public String getActiveApiVersion() { */ public String getActiveExecutionDriver() { if (!preconditionsChecked) { - client(true); + client(); } return activeExecutionDriver; } diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 934b6f78336..24c3415b6f2 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -261,12 +261,6 @@ public void stop() { } ResourceReaper.instance().stopAndRemoveContainer(containerId, imageName); - - try { - dockerClient.close(); - } catch (IOException e) { - logger().debug("Failed to close docker client"); - } } /** diff --git a/core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java b/core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java index b65f0221f17..7844d1a3afa 100644 --- a/core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java +++ b/core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java @@ -21,6 +21,7 @@ */ public abstract class DockerClientProviderStrategy { + protected DockerClient client; protected DockerClientConfig config; private static final RateLimiter PING_RATE_LIMITER = RateLimiterBuilder.newBuilder() @@ -93,7 +94,7 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List implements static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try (DockerClient dockerClientForCleaning = DockerClientFactory.instance().client(false)) { + DockerClient dockerClientForCleaning = DockerClientFactory.instance().client(); + try { for (String dockerImageName : imagesToDelete) { log.info("Removing image tagged {}", dockerImageName); try { @@ -48,7 +50,7 @@ public class ImageFromDockerfile extends LazyFuture implements log.warn("Unable to delete image " + dockerImageName, e); } } - } catch (IOException e) { + } catch (DockerClientException e) { throw new RuntimeException(e); } })); @@ -91,7 +93,8 @@ protected final String resolve() { Profiler profiler = new Profiler("Rule creation - build image"); profiler.setLogger(logger); - try (DockerClient dockerClient = DockerClientFactory.instance().client(false)) { + DockerClient dockerClient = DockerClientFactory.instance().client(); + try { if (deleteOnExit) { imagesToDelete.add(dockerImageName); } diff --git a/pom.xml b/pom.xml index 22086d49fc5..9dfe1227eed 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.testcontainers