Skip to content

Commit

Permalink
feat: support older docker versions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass authored Apr 30, 2024
1 parent 77f771c commit 131dc3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/local/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@ func New() (*Docker, error) {
}

var dockerCli *client.Client
dockerOpts := []client.Opt{client.FromEnv, client.WithAPIVersionNegotiation()}

switch runtime.GOOS {
case "darwin":
// on mac, sometimes the docker host isn't set correctly, if it fails check the home directory
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithHost("unix:///var/run/docker.sock"))
dockerCli, err = client.NewClientWithOpts(append(dockerOpts, client.WithHost("unix:///var/run/docker.sock"))...)
if err != nil {
// keep the original error, as we'll join with the next error (if another error occurs)
outerErr := err
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithHost(fmt.Sprintf("unix:///%s/.docker/run/docker.sock", userHome)))
// this works as the last WithHost call will win
dockerCli, err = client.NewClientWithOpts(append(dockerOpts, client.WithHost(fmt.Sprintf("unix:///%s/.docker/run/docker.sock", userHome)))...)
if err != nil {
err = fmt.Errorf("%w: %w", err, outerErr)
}
}
case "windows":
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithHost("npipe:////./pipe/docker_engine"))
dockerCli, err = client.NewClientWithOpts(append(dockerOpts, client.WithHost("npipe:////./pipe/docker_engine"))...)
default:
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithHost("unix:///var/run/docker.sock"))
dockerCli, err = client.NewClientWithOpts(append(dockerOpts, client.WithHost("unix:///var/run/docker.sock"))...)
}

if err != nil {
Expand Down

0 comments on commit 131dc3b

Please sign in to comment.