fix: Check the operating system for determining the default Docker socket (#427)

Windows doesn't use `/var/run/docker.sock`, so this provider
didn't work out of the box.
This commit is contained in:
Kyle Carberry 2022-08-10 08:32:34 -05:00 committed by GitHub
parent 78e4a2bbe4
commit 6c8714dc4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import (
"log"
"os"
"os/user"
"runtime"
"strings"
"github.com/docker/cli/cli/config/configfile"
@ -39,9 +40,17 @@ func New(version string) func() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"),
Type: schema.TypeString,
Required: true,
DefaultFunc: func() (interface{}, error) {
if v := os.Getenv("DOCKER_HOST"); v != "" {
return v, nil
}
if runtime.GOOS == "windows" {
return "npipe:////./pipe/docker_engine", nil
}
return "unix:///var/run/docker.sock", nil
},
Description: "The Docker daemon address",
},
"ssh_opts": {