Skip to content

Commit 9ac4297

Browse files
committed
fix: test_fix
1 parent f2a6fe9 commit 9ac4297

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ on:
1717
- 'RELEASING.md'
1818
- '.sdkmanrc'
1919
push:
20-
branches: [ main ]
20+
branches:
21+
- main
22+
- ci-check
2123
paths-ignore:
2224
- '.github/ISSUE_TEMPLATE/*.yaml'
2325
- '.github/CODEOWNERS'

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
import org.testcontainers.UnstableAPI;
2828
import org.testcontainers.utility.TestcontainersConfiguration;
2929

30+
import java.io.BufferedReader;
3031
import java.io.File;
32+
import java.io.IOException;
33+
import java.io.InputStreamReader;
3134
import java.net.InetSocketAddress;
3235
import java.net.Socket;
3336
import java.net.SocketAddress;
@@ -403,9 +406,20 @@ public static DockerClient getClientForConfig(TransportConfig transportConfig) {
403406

404407
DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();
405408

406-
if (configBuilder.build().getApiVersion() == RemoteApiVersion.UNKNOWN_VERSION) {
409+
410+
String dockerVersion = getDockerEngineVersionFromCli();
411+
System.out.println("Detected Docker Engine Version: " + dockerVersion);
412+
413+
if (isDockerVersionAtLeast(dockerVersion, 25)) {
407414
configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_44);
415+
} else {
416+
configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_32);
408417
}
418+
419+
// if (configBuilder.build().getApiVersion() == RemoteApiVersion.UNKNOWN_VERSION) {
420+
// configBuilder.withApiVersion(RemoteApiVersion.VERSION_1_44);
421+
// }
422+
409423
Map<String, String> headers = new HashMap<>();
410424
headers.put("x-tc-sid", DockerClientFactory.SESSION_ID);
411425
headers.put("User-Agent", String.format("tc-java/%s", DockerClientFactory.TESTCONTAINERS_VERSION));
@@ -466,4 +480,38 @@ static String resolveDockerHostIpAddress(DockerClient client, URI dockerHost, bo
466480
return null;
467481
}
468482
}
483+
484+
485+
private static String getDockerEngineVersionFromCli() {
486+
try {
487+
// dockerコマンドのパスが通っている前提
488+
ProcessBuilder pb = new ProcessBuilder("docker", "version", "--format", "{{.Server.Version}}");
489+
Process process = pb.start();
490+
491+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
492+
String version = reader.readLine();
493+
if (version != null) {
494+
return version.trim();
495+
}
496+
}
497+
} catch (IOException e) {
498+
log.warn("Failed to get docker version via CLI", e);
499+
}
500+
return "0.0.0";
501+
}
502+
503+
private static boolean isDockerVersionAtLeast(String versionString, int targetMajorVersion) {
504+
if (versionString == null || versionString.isEmpty()) return false;
505+
506+
try {
507+
String majorPart = versionString.split("\\.")[0];
508+
int majorVersion = Integer.parseInt(majorPart);
509+
510+
return majorVersion >= targetMajorVersion;
511+
} catch (NumberFormatException e) {
512+
log.warn("Failed to parse docker version string: {}", versionString);
513+
return false;
514+
}
515+
}
516+
469517
}

0 commit comments

Comments
 (0)