Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
make weave and the proxy work with tcp-only dockers via DOCKER_HOST
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Nov 30, 2015
1 parent 6e97eba commit 3081a73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions common/docker/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package docker

import (
"strings"

"github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common"
)
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ func main() {
dnsEffectiveListenAddress string
iface *net.Interface
datapathName string

defaultDockerHost = "unix:///var/run/docker.sock"
)

if val := os.Getenv("DOCKER_HOST"); val != "" {
defaultDockerHost = val
}

mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
mflag.BoolVar(&createDatapath, []string{"-create-datapath"}, false, "create ODP datapath and exit")
mflag.BoolVar(&deleteDatapath, []string{"-delete-datapath"}, false, "delete ODP datapath and exit")
Expand All @@ -92,7 +98,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"}, defaultDockerHost, "Docker API endpoint")
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")
Expand Down
16 changes: 12 additions & 4 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -121,6 +125,7 @@ exec_remote() {
-e WEAVE_MTU \
-e WEAVE_NO_FASTDP \
-e WEAVE_NO_BRIDGED_FASTDP \
-e DOCKER_HOST \
-e DOCKER_BRIDGE \
-e DOCKER_CLIENT_HOST="$DOCKER_CLIENT_HOST" \
-e DOCKER_CLIENT_TLS_VERIFY="$DOCKER_CLIENT_TLS_VERIFY" \
Expand Down Expand Up @@ -1597,6 +1602,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 \
Expand All @@ -1606,7 +1612,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
}
Expand Down Expand Up @@ -1660,6 +1666,7 @@ launch_proxy() {
-v /proc:/hostproc \
-e PROCFS=/hostproc \
-e WEAVE_CIDR=none \
-e DOCKER_HOST \
-e DOCKER_BRIDGE \
-e WEAVE_DEBUG \
-e COVERAGE \
Expand All @@ -1679,6 +1686,7 @@ launch_plugin() {
--net=host \
$(docker_sock_volume_mount) \
-v /run/docker/plugins:/run/docker/plugins \
-e DOCKER_HOST \
$PLUGIN_IMAGE "$@")
}

Expand Down

0 comments on commit 3081a73

Please sign in to comment.