Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit cfa212f

Browse files
committed
Fall back to global CLI socket on Linux
DD relies on having the CLI socket available in /var/run when running in WSL. So in case we can't find the CLI socket in the calling user's home directory, fall back to /var/run. Signed-off-by: Piotr Stankiewicz <[email protected]>
1 parent 2d878f7 commit cfa212f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cli/metrics/conn_other.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ package metrics
2121

2222
import (
2323
"net"
24+
"os"
2425
"path/filepath"
2526

2627
"github.com/docker/docker/pkg/homedir"
2728
)
2829

2930
var (
30-
socket = ""
31+
socket = "/var/run/docker-cli.sock"
3132
)
3233

3334
func init() {
3435
// Attempt to retrieve the Docker CLI socket for the current user.
3536
if home := homedir.Get(); home != "" {
36-
socket = filepath.Join(home, ".docker/desktop/docker-cli.sock")
37-
} // else: On Linux we don't expect to have a global CLI socket, so leave it empty and let connections fail.
38-
overrideSocket() // nop, unless built for e2e testing
37+
tmp := filepath.Join(home, ".docker/desktop/docker-cli.sock")
38+
if _, err := os.Stat(tmp); err == nil {
39+
socket = tmp
40+
} // else: fall back to the global CLI socket path (used by DD in WSL)
41+
} // else: fall back to the global CLI socket path (used by DD in WSL)
42+
overrideSocket() // no-op, unless built for e2e testing
3943
}
4044

4145
func conn() (net.Conn, error) {

0 commit comments

Comments
 (0)