Skip to content

Commit 0ad0614

Browse files
committed
Fix compatibility with older Docker Engines by falling back to v1.32
Previously, minimum Docker API version was raised to v1.44 to keep compatibility with most recent Docker Enginer API. This commit introduces a fallback to API v1.32, which was used before. Fixes #11232
1 parent 3fe0976 commit 0ad0614

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,34 @@ public static DockerClient getClientForConfig(TransportConfig transportConfig) {
401401
throw new IllegalArgumentException("Unknown transport type '" + transportType + "'");
402402
}
403403

404-
DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();
404+
DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig
405+
.createDefaultConfigBuilder()
406+
.withDockerHost(transportConfig.getDockerHost().toString());
405407

406-
if (configBuilder.build().getApiVersion() == RemoteApiVersion.UNKNOWN_VERSION) {
407-
configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_44);
408-
}
409408
Map<String, String> headers = new HashMap<>();
410409
headers.put("x-tc-sid", DockerClientFactory.SESSION_ID);
411410
headers.put("User-Agent", String.format("tc-java/%s", DockerClientFactory.TESTCONTAINERS_VERSION));
412411

413-
return DockerClientImpl.getInstance(
414-
new AuthDelegatingDockerClientConfig(
415-
configBuilder.withDockerHost(transportConfig.getDockerHost().toString()).build()
416-
),
417-
new HeadersAddingDockerHttpClient(dockerHttpClient, headers)
418-
);
412+
try {
413+
if (configBuilder.build().getApiVersion() == RemoteApiVersion.UNKNOWN_VERSION) {
414+
configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_44);
415+
}
416+
DockerClient client = DockerClientImpl.getInstance(
417+
new AuthDelegatingDockerClientConfig(configBuilder.build()),
418+
new HeadersAddingDockerHttpClient(dockerHttpClient, headers)
419+
);
420+
log.debug("Pinging Docker API version 1.44.");
421+
client.pingCmd().exec();
422+
return client;
423+
} catch (Exception ex) {
424+
log.debug("Fallback to Docker API version 1.32.");
425+
return DockerClientImpl.getInstance(
426+
new AuthDelegatingDockerClientConfig(
427+
configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_32).build()
428+
),
429+
new HeadersAddingDockerHttpClient(dockerHttpClient, headers)
430+
);
431+
}
419432
}
420433

421434
public synchronized String getDockerHostIpAddress() {

0 commit comments

Comments
 (0)