From 7860eaa24392fa1d7d401ff039fc0b9a1570435d Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 20 Nov 2015 12:39:57 +0000 Subject: [PATCH] make weave and the proxy work with tcp-only dockers via DOCKER_HOST --- common/docker/client.go | 8 ++++++++ prog/weaver/main.go | 2 +- weave | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/common/docker/client.go b/common/docker/client.go index 6a4eaff1de..abbb85a277 100644 --- a/common/docker/client.go +++ b/common/docker/client.go @@ -1,6 +1,8 @@ package docker import ( + "strings" + "github.com/fsouza/go-dockerclient" . "github.com/weaveworks/weave/common" ) @@ -17,6 +19,9 @@ type Client struct { // NewClient creates a new Docker client and checks we can talk to Docker func NewClient(apiPath string) (*Client, error) { + if apiPath != "" && !strings.Contains(apiPath, "://") { + apiPath = "tcp://" + apiPath + } dc, err := docker.NewClient(apiPath) if err != nil { return nil, err @@ -27,6 +32,9 @@ func NewClient(apiPath string) (*Client, error) { } func NewVersionedClient(apiPath string, apiVersionString string) (*Client, error) { + if !strings.Contains(apiPath, "://") { + apiPath = "tcp://" + apiPath + } dc, err := docker.NewVersionedClient(apiPath, apiVersionString) if err != nil { return nil, err diff --git a/prog/weaver/main.go b/prog/weaver/main.go index d5fb2553e0..425718f6d3 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -92,7 +92,7 @@ func main() { mflag.StringVar(&iprangeCIDR, []string{"#iprange", "#-iprange", "-ipalloc-range"}, "", "IP address range reserved for automatic allocation, in CIDR notation") mflag.StringVar(&ipsubnetCIDR, []string{"#ipsubnet", "#-ipsubnet", "-ipalloc-default-subnet"}, "", "subnet to allocate within by default, in CIDR notation") mflag.IntVar(&peerCount, []string{"#initpeercount", "#-initpeercount", "-init-peer-count"}, 0, "number of peers in network (for IP address allocation)") - mflag.StringVar(&dockerAPI, []string{"#api", "#-api", "-docker-api"}, "", "Docker API endpoint, e.g. unix:///var/run/docker.sock") + mflag.StringVar(&dockerAPI, []string{"#api", "#-api", "-docker-api"}, os.Getenv("DOCKER_HOST"), "Docker API endpoint, e.g. unix:///var/run/docker.sock") mflag.BoolVar(&noDNS, []string{"-no-dns"}, false, "disable DNS server") mflag.StringVar(&dnsDomain, []string{"-dns-domain"}, nameserver.DefaultDomain, "local domain to server requests for") mflag.StringVar(&dnsListenAddress, []string{"-dns-listen-address"}, nameserver.DefaultListenAddress, "address to listen on for DNS requests") diff --git a/weave b/weave index 7c12e0a668..dc866ab39c 100755 --- a/weave +++ b/weave @@ -94,15 +94,19 @@ usage() { } docker_sock() { + if [ -z "$DOCKER_HOST" ]; then + echo "/var/run/docker.sock" + return + fi if echo "$DOCKER_HOST" | grep -q "^unix://" >/dev/null; then echo "${DOCKER_HOST#unix://}" - else - echo "/var/run/docker.sock" fi } docker_sock_volume_mount() { - echo "-v $(docker_sock):$(docker_sock) -e DOCKER_HOST=unix://$(docker_sock)" + if [ -n "$(docker_sock)" ]; then + echo "-v $(docker_sock):$(docker_sock)" + fi } exec_remote() { @@ -120,6 +124,7 @@ exec_remote() { -e WEAVE_CONTAINER_NAME \ -e WEAVE_MTU \ -e WEAVE_NO_FASTDP \ + -e DOCKER_HOST \ -e DOCKER_BRIDGE \ -e DOCKER_CLIENT_HOST="$DOCKER_CLIENT_HOST" \ -e DOCKER_CLIENT_TLS_VERIFY="$DOCKER_CLIENT_TLS_VERIFY" \ @@ -1492,6 +1497,7 @@ launch_router() { $(docker_sock_volume_mount) \ -p $PORT:$CONTAINER_PORT/tcp -p $PORT:$CONTAINER_PORT/udp \ ${NETHOST_OPT:-$DNS_PORT_MAPPING} \ + -e DOCKER_HOST \ -e WEAVE_PASSWORD \ -e WEAVE_CIDR=none \ $WEAVE_DOCKER_ARGS $IMAGE $COVERAGE_ARGS \ @@ -1501,7 +1507,7 @@ launch_router() { --dns-effective-listen-address $DOCKER_BRIDGE_IP \ ${NETHOST_OPT:+$DNS_ROUTER_OPTS} $NO_DNS_OPT \ --http-addr $HTTP_IP:$HTTP_PORT \ - --docker-api "unix://$(docker_sock)" "$@") + "$@") with_container_netns_or_die $CONTAINER_NAME setup_router_iface_$BRIDGE_TYPE attach_router } @@ -1553,6 +1559,7 @@ launch_proxy() { -v /proc:/hostproc \ -e PROCFS=/hostproc \ -e WEAVE_CIDR=none \ + -e DOCKER_HOST \ -e DOCKER_BRIDGE \ -e WEAVE_DEBUG \ -e COVERAGE \ @@ -1572,6 +1579,7 @@ launch_plugin() { --net=host \ $(docker_sock_volume_mount) \ -v /run/docker/plugins:/run/docker/plugins \ + -e DOCKER_HOST \ $PLUGIN_IMAGE "$@") }