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

Commit

Permalink
Fall back to global CLI socket on Linux
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
p1-0tr committed Jul 25, 2022
1 parent 2d878f7 commit cfa212f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cli/metrics/conn_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ package metrics

import (
"net"
"os"
"path/filepath"

"github.com/docker/docker/pkg/homedir"
)

var (
socket = ""
socket = "/var/run/docker-cli.sock"
)

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

func conn() (net.Conn, error) {
Expand Down

0 comments on commit cfa212f

Please sign in to comment.