Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions kurtosis-devnet/pkg/build/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package build
import (
"bytes"
"context"
"errors"
"fmt"
"log"
"net/url"
"os"
"os/exec"
"runtime"
"strings"
"text/template"

Expand Down Expand Up @@ -56,29 +56,35 @@ func (p *defaultDockerProvider) newClient() (dockerClient, error) {
opts := []client.Opt{client.FromEnv}

// Check if default docker socket exists
hostURL, err := client.ParseHostURL(client.DefaultDockerHost)
hostURL, err := url.Parse(client.DefaultDockerHost)
if err != nil {
return nil, fmt.Errorf("failed to parse default docker host: %w", err)
}

// For unix sockets, check if the socket file exists
if hostURL.Scheme == "unix" {
unixOS := runtime.GOOS == "linux" || runtime.GOOS == "darwin"
if hostURL.Scheme == "unix" && unixOS {
if _, err := os.Stat(hostURL.Path); os.IsNotExist(err) {
// Default socket doesn't exist, try alternate location. Docker Desktop uses ~/.docker/run/docker.sock
// Default socket doesn't exist, try to find an alternate location. Docker Desktop uses a socket in the home directory.
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("failed to get user home directory: %w", err)
}
// Try to use the non-privileged socket if available
homeSocketPath := fmt.Sprintf("%s/.docker/run/docker.sock", homeDir)
if _, err := os.Stat(homeSocketPath); os.IsNotExist(err) {
return nil, errors.New("failed to find docker socket")
if runtime.GOOS == "linux" {
homeSocketPath = fmt.Sprintf("%s/.docker/desktop/docker.sock", homeDir)
}
socketURL := &url.URL{
Scheme: "unix",
Path: homeSocketPath,

// If that socket exists, make it the default. Otherwise, leave it alone, and hope some environment variable has been set.
if _, err := os.Stat(homeSocketPath); err == nil {
socketURL := &url.URL{
Scheme: "unix",
Path: homeSocketPath,
}
// prepend the host, so that it can still be overridden by the environment.
opts = append([]client.Opt{client.WithHost(socketURL.String())}, opts...)
}
// prepend the host, so that it can still be overridden by the environment.
opts = append([]client.Opt{client.WithHost(socketURL.String())}, opts...)
}
}

Expand Down