Skip to content

Commit 43a570b

Browse files
committed
Fix docker socket mount for Windows
1 parent 5dcb7b3 commit 43a570b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

internal/runtime/docker.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,19 @@ func probeSocket(candidates ...string) string {
7272
}
7373

7474
func (d *DockerRuntime) SocketPath() string {
75-
host := d.client.DaemonHost()
75+
return socketPathFromHost(d.client.DaemonHost())
76+
}
77+
78+
// Resolves the host-side Docker socket path to bind-mount into containers.
79+
// On Unix, it strips the unix:// prefix. On Windows, Docker Desktop connects via a named pipe
80+
// but exposes the socket at /var/run/docker.sock for Linux containers to bind-mount (via WSL2).
81+
func socketPathFromHost(host string) string {
7682
if strings.HasPrefix(host, "unix://") {
7783
return strings.TrimPrefix(host, "unix://")
7884
}
85+
if strings.HasPrefix(host, "npipe://") {
86+
return "/var/run/docker.sock"
87+
}
7988
return ""
8089
}
8190

internal/runtime/docker_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ func TestSocketPath_ReturnsEmptyForTCPHost(t *testing.T) {
5656
assert.Equal(t, "", rt.SocketPath())
5757
}
5858

59+
func TestSocketPathFromHost_ReturnsDockerSockForWindowsNamedPipe(t *testing.T) {
60+
assert.Equal(t, "/var/run/docker.sock", socketPathFromHost("npipe:////./pipe/docker_engine"))
61+
}
62+
63+
func TestSocketPathFromHost_ExtractsUnixPath(t *testing.T) {
64+
assert.Equal(t, "/var/run/docker.sock", socketPathFromHost("unix:///var/run/docker.sock"))
65+
}
66+
5967
func TestWindowsDockerStartCommand_DockerAvailable(t *testing.T) {
6068
lookPath := func(string) (string, error) { return "/usr/bin/docker", nil }
6169
assert.Equal(t, "docker desktop start", windowsDockerStartCommand(func(string) string { return "" }, lookPath))

0 commit comments

Comments
 (0)