From 927bb2547a6024508d23392411256b10be53e205 Mon Sep 17 00:00:00 2001 From: Roland Schilter Date: Wed, 21 Jun 2017 16:27:04 +0200 Subject: [PATCH] Honor DOCKER_* env variables in probe and app Changed default for flag `-app.docker` to use the DOCKER_* env variables instead of hardcoded /var/run/docker.sock; uses docker's default if no DOCKER_HOST defined, for both probe and app. Fixes #1975 --- app/weave.go | 7 +++---- probe/docker/registry.go | 3 +++ probe/overlay/weave.go | 3 +++ prog/main.go | 4 ++-- prog/probe.go | 4 +--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/weave.go b/app/weave.go index 7ea3711700..fb7fe35a99 100644 --- a/app/weave.go +++ b/app/weave.go @@ -12,10 +12,9 @@ import ( // Default values for weave app integration const ( - DefaultHostname = "scope.weave.local." - DefaultWeaveURL = "http://127.0.0.1:6784" - DefaultContainerName = "weavescope" - DefaultDockerEndpoint = "unix:///var/run/docker.sock" + DefaultHostname = "scope.weave.local." + DefaultWeaveURL = "http://127.0.0.1:6784" + DefaultContainerName = "weavescope" ) // WeavePublisher is a thing which periodically registers this app with WeaveDNS. diff --git a/probe/docker/registry.go b/probe/docker/registry.go index 1082def1c1..223b115759 100644 --- a/probe/docker/registry.go +++ b/probe/docker/registry.go @@ -92,6 +92,9 @@ type Client interface { } func newDockerClient(endpoint string) (Client, error) { + if endpoint == "" { + return docker_client.NewClientFromEnv() + } return docker_client.NewClient(endpoint) } diff --git a/probe/overlay/weave.go b/probe/overlay/weave.go index b87cb88eb6..19eca7d22c 100644 --- a/probe/overlay/weave.go +++ b/probe/overlay/weave.go @@ -153,6 +153,9 @@ type DockerClient interface { } func newDockerClient(endpoint string) (DockerClient, error) { + if endpoint == "" { + return docker_client.NewClientFromEnv() + } return docker_client.NewClient(endpoint) } diff --git a/prog/main.go b/prog/main.go index c1578ad83f..ecb9d3d30b 100644 --- a/prog/main.go +++ b/prog/main.go @@ -337,7 +337,7 @@ func setupFlags(flags *flags) { flag.StringVar(&flags.app.weaveAddr, "app.weave.addr", app.DefaultWeaveURL, "Address on which to contact WeaveDNS") flag.StringVar(&flags.app.weaveHostname, "app.weave.hostname", "", "Hostname to advertise in WeaveDNS") flag.StringVar(&flags.app.containerName, "app.container.name", app.DefaultContainerName, "Name of this container (to lookup container ID)") - flag.StringVar(&flags.app.dockerEndpoint, "app.docker", app.DefaultDockerEndpoint, "Location of docker endpoint (to lookup container ID)") + flag.StringVar(&flags.app.dockerEndpoint, "app.docker", "", "Overwrite location of docker endpoint (to lookup container ID) (default \"$DOCKER_HOST\")") flag.Var(&flags.containerLabelFilterFlags, "app.container-label-filter", "Add container label-based view filter, specified as title:label. Multiple flags are accepted. Example: --app.container-label-filter='Database Containers:role=db'") flag.Var(&flags.containerLabelFilterFlagsExclude, "app.container-label-filter-exclude", "Add container label-based view filter that excludes containers with the given label, specified as title:label. Multiple flags are accepted. Example: --app.container-label-filter-exclude='Database Containers:role=db'") @@ -394,7 +394,7 @@ func main() { if flags.probe.httpListen != "" { _, _, err := net.SplitHostPort(flags.probe.httpListen) if err != nil { - log.Fatalf("Invalid value for -app.http.address: %v", err) + log.Fatalf("Invalid value for -probe.http.address: %v", err) } } diff --git a/prog/probe.go b/prog/probe.go index 1fe6d95e57..cbe544d5a3 100644 --- a/prog/probe.go +++ b/prog/probe.go @@ -42,7 +42,6 @@ const ( var ( pluginAPIVersion = "1" - dockerEndpoint = "unix:///var/run/docker.sock" ) func checkNewScopeVersion(flags probeFlags) { @@ -199,7 +198,6 @@ func probeMain(flags probeFlags, targets []appclient.Target) { CollectStats: true, HostID: hostID, HandlerRegistry: handlerRegistry, - DockerEndpoint: dockerEndpoint, NoCommandLineArguments: flags.noCommandLineArguments, NoEnvironmentVariables: flags.noEnvironmentVariables, } @@ -236,7 +234,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) { if flags.weaveEnabled { client := weave.NewClient(sanitize.URL("http://", 6784, "")(flags.weaveAddr)) - weave, err := overlay.NewWeave(hostID, client, dockerEndpoint) + weave, err := overlay.NewWeave(hostID, client, "") if err != nil { log.Errorf("Weave: failed to start client: %v", err) } else {