Skip to content

Commit 8e94b84

Browse files
committed
Fix bind mounts for ResourceReaper/ryuk and ContainerisedDockerCompose
Relates to #545 Relates to testcontainers#2998
1 parent 6bdbc8f commit 8e94b84

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

core/src/main/java/org/testcontainers/DockerClientFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import lombok.Synchronized;
2020
import lombok.extern.slf4j.Slf4j;
2121
import org.apache.commons.lang.StringUtils;
22+
import org.apache.commons.lang.SystemUtils;
2223
import org.testcontainers.dockerclient.DockerClientProviderStrategy;
2324
import org.testcontainers.dockerclient.DockerMachineClientProviderStrategy;
2425
import org.testcontainers.dockerclient.TransportConfig;
@@ -145,9 +146,12 @@ public String getRemoteDockerUnixSocketPath() {
145146
}
146147

147148
URI dockerHost = getTransportConfig().getDockerHost();
148-
return "unix".equals(dockerHost.getScheme())
149+
String path = "unix".equals(dockerHost.getScheme())
149150
? dockerHost.getRawPath()
150151
: "/var/run/docker.sock";
152+
return SystemUtils.IS_OS_WINDOWS
153+
? "/" + path
154+
: path;
151155
}
152156

153157
/**

core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {
608608
// as the docker daemon, just mapping the docker control socket is OK.
609609
// As there seems to be a problem with mapping to the /var/run directory in certain environments (e.g. CircleCI)
610610
// we map the socket file outside of /var/run, as just /docker.sock
611-
addFileSystemBind("/" + DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/docker.sock", READ_WRITE);
611+
addFileSystemBind(DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/docker.sock", READ_WRITE);
612612
addEnv("DOCKER_HOST", "unix:///docker.sock");
613613
setStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy());
614614
setWorkingDirectory(containerPwd);

core/src/main/java/org/testcontainers/utility/ResourceReaper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static String start(String hostIpAddress, DockerClient client) {
7676
DockerClientFactory.instance().checkAndPullImage(client, ryukImage);
7777

7878
List<Bind> binds = new ArrayList<>();
79-
binds.add(new Bind("/" + DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), new Volume("/var/run/docker.sock")));
79+
binds.add(new Bind(DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), new Volume("/var/run/docker.sock")));
8080

8181
String ryukContainerId = client.createContainerCmd(ryukImage)
8282
.withHostConfig(new HostConfig().withAutoRemove(true))

0 commit comments

Comments
 (0)