Allow docker API location to be specified or blanked

This commit is contained in:
Bryan Boreham committed 2017-04-12 13:05:39 +00:00
1 parent 0af2111535
commit 0c23e47124
1 file changed
+21 -5
+21 -5
View File
@@ -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 {