Skip to content

Commit 0bf52a9

Browse files
authored
Add docker rootless support for macOS and desktop for Linux (#6907)
Docker Desktop for Linux installs the socket path at `/home/username/.docker/desktop/docker.sock`. In Docker Desktop for Mac 4.18, there is an option to disable the default Docker socket (/var/run/docker.sock) and rely on `/home/username/.docker/run/docker.sock` instead. Fixes #6426
1 parent 3d21747 commit 0bf52a9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ private Path resolveSocketPath() {
3434
Path homePath = Paths.get(System.getProperty("user.home")).resolve(".docker").resolve("run");
3535
return tryFolder(homePath)
3636
.orElseGet(() -> {
37-
Path implicitPath = Paths.get("/run/user/" + LibC.INSTANCE.getuid());
38-
return tryFolder(implicitPath).orElse(null);
37+
Path dockerDesktopPath = Paths
38+
.get(System.getProperty("user.home"))
39+
.resolve(".docker")
40+
.resolve("desktop");
41+
return tryFolder(dockerDesktopPath)
42+
.orElseGet(() -> {
43+
Path implicitPath = Paths.get("/run/user/" + LibC.INSTANCE.getuid());
44+
return tryFolder(implicitPath).orElse(null);
45+
});
3946
});
4047
});
4148
}
@@ -79,7 +86,11 @@ public TransportConfig getTransportConfig() throws InvalidConfigurationException
7986

8087
@Override
8188
protected boolean isApplicable() {
82-
return SystemUtils.IS_OS_LINUX && getSocketPath() != null && Files.exists(getSocketPath());
89+
return (
90+
(SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) &&
91+
getSocketPath() != null &&
92+
Files.exists(getSocketPath())
93+
);
8394
}
8495

8596
@Override

0 commit comments

Comments
 (0)