Skip to content

Commit

Permalink
Fix bind mounts for ResourceReaper/ryuk and ContainerisedDockerCompose
Browse files Browse the repository at this point in the history
Relates to #545
Relates to testcontainers#2998
  • Loading branch information
gesellix committed Aug 28, 2020
1 parent 6bdbc8f commit 3797957
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.testcontainers.dockerclient.DockerClientProviderStrategy;
import org.testcontainers.dockerclient.DockerMachineClientProviderStrategy;
import org.testcontainers.dockerclient.TransportConfig;
Expand Down Expand Up @@ -145,9 +146,12 @@ public String getRemoteDockerUnixSocketPath() {
}

URI dockerHost = getTransportConfig().getDockerHost();
return "unix".equals(dockerHost.getScheme())
String path = "unix".equals(dockerHost.getScheme())
? dockerHost.getRawPath()
: "/var/run/docker.sock";
return SystemUtils.IS_OS_WINDOWS
? "/" + path
: path;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {
// as the docker daemon, just mapping the docker control socket is OK.
// As there seems to be a problem with mapping to the /var/run directory in certain environments (e.g. CircleCI)
// we map the socket file outside of /var/run, as just /docker.sock
addFileSystemBind("/" + DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/docker.sock", READ_WRITE);
addFileSystemBind(DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/docker.sock", READ_WRITE);
addEnv("DOCKER_HOST", "unix:///docker.sock");
setStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy());
setWorkingDirectory(containerPwd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static String start(String hostIpAddress, DockerClient client) {
DockerClientFactory.instance().checkAndPullImage(client, ryukImage);

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

String ryukContainerId = client.createContainerCmd(ryukImage)
.withHostConfig(new HostConfig().withAutoRemove(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.rnorth.ducttape.Preconditions;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.ComparableVersion;
Expand Down Expand Up @@ -84,7 +85,7 @@ public LocalStackContainer(final DockerImageName dockerImageName, boolean useLeg
super(dockerImageName);
this.legacyMode = useLegacyMode;

withFileSystemBind("//var/run/docker.sock", "/var/run/docker.sock");
withFileSystemBind(DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/var/run/docker.sock");
waitingFor(Wait.forLogMessage(".*Ready\\.\n", 1));
}

Expand Down

0 comments on commit 3797957

Please sign in to comment.