Skip to content

Commit

Permalink
fix: mount of socket from Docker Desktop (#2350)
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vašek <[email protected]>
  • Loading branch information
matejvasek authored Jun 12, 2024
1 parent 2e7154c commit a18957d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/docker/cli/cli/config"
Expand Down Expand Up @@ -90,8 +91,8 @@ func NewClient(defaultHost string) (dockerClient client.CommonAPIClient, dockerH
dockerHostInRemote = ""
}

if isUnix && runtime.GOOS == "darwin" {
// A unix socket on macOS is most likely tunneled from VM,
if isUnix && (runtime.GOOS == "darwin" || strings.HasSuffix(dockerHost, ".docker/desktop/docker.sock")) {
// The unix socket is most likely tunneled from VM,
// so it cannot be mounted under that path.
dockerHostInRemote = ""
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/docker/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ func TestNewClient_DockerHost(t *testing.T) {
dockerHostEnvVar: "unix:///some/path/docker.sock",
expectedRemoteDockerHost: map[string]string{"darwin": "", "windows": "", "linux": "unix:///some/path/docker.sock"},
},
{
name: "Docker Desktop",
dockerHostEnvVar: "unix:///home/jdoe/.docker/desktop/docker.sock",
expectedRemoteDockerHost: map[string]string{"darwin": "", "windows": "", "linux": ""},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.name == "unix" && runtime.GOOS == "windows" {
if strings.HasPrefix(tt.dockerHostEnvVar, "unix") && runtime.GOOS == "windows" {
t.Skip("Windows cannot handle Unix sockets")
}

Expand Down

0 comments on commit a18957d

Please sign in to comment.