Skip to content

Commit

Permalink
Fix bind mounts for ResourceReaper/ryuk and ContainerisedDockerCompos…
Browse files Browse the repository at this point in the history
…e on macOS (#3159)

Relates to #545
Relates to #2998
  • Loading branch information
gesellix authored Aug 29, 2020
1 parent 87571b6 commit 8bc3bf8
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

4 comments on commit 8bc3bf8

@chriswininger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait for this to be in a non-rc release. This is definitely biting me on OSX right now :-(

Nice job on the fix

@bsideup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriswininger any reason why you don't want to try the rc? It is only rc and not the release because we want to hear feedback on some new APIs and deprecations, but the "core" of it is the same as will go into the release version

@bsideup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can disable the gRPC FUSE to workaround it

@chriswininger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriswininger any reason why you don't want to try the rc? It is only rc and not the release because we want to hear feedback on some new APIs and deprecations, but the "core" of it is the same as will go into the release version

I have tried the RC and can verify it absolutely fixes the problem, but I'm not comfortable using an rc in our production code.

Thanks for the tip on the workaround though.

Please sign in to comment.