Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 77e61c2

Browse files
authored
Merge pull request #2177 from p1-0tr/ps-global-cli-sock-fallback
Fall back to global CLI socket on Linux
2 parents 2d878f7 + cfa212f commit 77e61c2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cli/metrics/conn_other.go

+8-4
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)