diff --git a/provider/image.go b/provider/image.go index 7359fdfa..0dd409c9 100644 --- a/provider/image.go +++ b/provider/image.go @@ -777,24 +777,44 @@ func configureDockerClient(configs map[string]string, verify bool) (*client.Clie return cli, err } - // Check if the connection works. If not and we used the default host, try the user host. + // Check if the connection works. If not and we used the default host, try the possible user hosts. // See "Adminless install on macOS" on https://www.docker.com/blog/docker-desktop-4-18/ - log.Printf("checking connection to docker daemon at %s", host) - _, err = cli.Ping(context.Background()) - if err != nil && !isExplicitHost && runtime.GOOS != "windows" { + testConnection := func(cli *client.Client) bool { + _, err = cli.Ping(context.Background()) + if err != nil { + log.Printf("error connecting to docker daemon at %s: %v", cli.DaemonHost(), err) + return false + } else { + log.Printf("successful connection to docker daemon at %s", cli.DaemonHost()) + return true + } + } + + success := testConnection(cli) + if !success && !isExplicitHost && runtime.GOOS != "windows" { home, err2 := os.UserHomeDir() if err2 != nil { return nil, err2 } - userSock := fmt.Sprintf("unix://%s/.docker/run/docker.sock", home) - log.Printf("no connection to docker daemon at %s, trying %s (%v)", host, userSock, err) - cli, err = configureDockerClientInner(configs, userSock) - if err != nil { - log.Printf("no connection to docker daemon at %s, stopping (%v)", host, err) + + userHosts := []string{"unix://%s/.docker/run/docker.sock", "unix://%s/.docker/desktop/docker.sock"} + for _, userHost := range userHosts { + userSock := fmt.Sprintf(userHost, home) + cli, err = configureDockerClientInner(configs, userSock) + if err != nil { + return cli, err + } + if testConnection(cli) { + success = true + break + } } } - return cli, err + if success { + return cli, err + } + return nil, fmt.Errorf("failed to connect to any docker daemon") } func configureDockerClientInner(configs map[string]string, host string) (*client.Client, error) {