diff --git a/prog/plugin/main.go b/prog/plugin/main.go index 6e36d8ec..3084f219 100644 --- a/prog/plugin/main.go +++ b/prog/plugin/main.go @@ -28,14 +28,22 @@ var Log = common.Log func main() { var ( justVersion bool + dockerAPI string address string meshAddress string logLevel string noMulticastRoute bool + + defaultDockerHost = "unix:///var/run/docker.sock" ) + if val := os.Getenv("DOCKER_HOST"); val != "" { + defaultDockerHost = val + } + flag.BoolVar(&justVersion, "version", false, "print version and exit") flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)") + flag.StringVar(&dockerAPI, "docker-api", defaultDockerHost, "Docker API endpoint") flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen") flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode") flag.BoolVar(&noMulticastRoute, "no-multicast-route", false, "deprecated (this is now the default)") @@ -51,17 +59,25 @@ func main() { weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log) - // API 1.21 is the first version that supports docker network commands - dockerClient, err := docker.NewVersionedClientFromEnv("1.21") - if err != nil { - Log.Fatalf("unable to connect to docker: %s", err) + var dockerClient *docker.Client + var err error + if dockerAPI != "" { + // API 1.21 is the first version that supports docker network commands + dockerClient, err = docker.NewVersionedClient(dockerAPI, "1.21") + if err != nil { + Log.Fatalf("unable to connect to docker: %s", err) + } } Log.Println("Weave plugin", version, "Command line options:", os.Args[1:]) if noMulticastRoute { Log.Warning("--no-multicast-route option has been removed; multicast is off by default") } - Log.Info(dockerClient.Info()) + if dockerClient == nil { + Log.Info("Running without Docker API connection") + } else { + Log.Info(dockerClient.Info()) + } err = run(dockerClient, weave, address, meshAddress) if err != nil {