From 272e63643cb029f1d4eee1c31502e700d380537b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 12 Apr 2015 21:58:20 +0100 Subject: [PATCH] make weave port configurable via WEAVE_PORT We cannot just leave that to the `-port` parameter since that only controls the container internal port weave is listening on (and uses as the default destination port for outbound connections). Also, we need the port for connection tracking cleanup during `stop` and `reset`. So we make setting `WEAVE_PORT` the only documented mechanism for overriding the port, and let `-port` set the container internal port only (and the script pays attentiont to that, so it can establish the correct port mapping). --- README.md | 9 +++++---- site/features.md | 5 ++++- weave | 13 ++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1f00d615..a9a6ab60 100644 --- a/README.md +++ b/README.md @@ -92,10 +92,11 @@ We repeat similar steps on `$HOST2`... The only difference, apart from the choice of IP address for the application container, is that we tell our weave that it should peer -with the weave on `$HOST1` (specified as the IP address or hostname, and -optional `:port`, by which `$HOST2` can reach it). NB: if there is a -firewall between `$HOST1` and `$HOST2`, you must open port 6783 for TCP -and UDP. +with the weave on `$HOST1` (specified as the IP address or hostname, +and optional `:port`, by which `$HOST2` can reach it). NB: if there is +a firewall between `$HOST1` and `$HOST2`, you must open the weave port +(6783 by default; this can be overriden by setting `WEAVE_PORT`) for +TCP and UDP. Note that we could instead have told the weave on `$HOST1` to connect to `$HOST2`, or told both about each other. Order does not matter here; diff --git a/site/features.md b/site/features.md index de64420f..cf96f48f 100644 --- a/site/features.md +++ b/site/features.md @@ -316,7 +316,10 @@ data centres. So, for example, one could run an application consisting of containers on GCE, EC2 and in local data centres. To enable this, the network must be configured to permit TCP and UDP -connections to port 6783 of the docker hosts. +connections to the weave port of the docker hosts. The weave port +defaults to 6783. This can be overriden by setting `WEAVE_PORT`, but +it is highly recommended that all peers in a weave network are given +the same port setting. ### Multi-hop routing diff --git a/weave b/weave index 01a9d7de..aed3d8af 100755 --- a/weave +++ b/weave @@ -59,6 +59,7 @@ exec_remote() { -e WEAVE_DOCKER_ARGS \ -e WEAVEDNS_DOCKER_ARGS \ -e WEAVE_PASSWORD \ + -e WEAVE_PORT \ -e WEAVE_CONTAINER_NAME \ -e DOCKER_BRIDGE \ -e PROCFS=/hostproc --privileged --net=host \ @@ -86,7 +87,7 @@ DNS_CONTAINER_NAME=weavedns BRIDGE=weave CONTAINER_IFNAME=ethwe MTU=65535 -PORT=6783 +PORT=${WEAVE_PORT:-6783} HTTP_PORT=6784 DNS_HTTP_PORT=6785 @@ -599,6 +600,7 @@ case "$COMMAND" in shift 1 fi NICKNAME=$(hostname) + CONTAINER_PORT=$PORT while true; do case "$1" in -password) @@ -612,6 +614,11 @@ case "$COMMAND" in NICKNAME="$2" shift 2 ;; + -port) + [ $# -gt 1 ] || usage + CONTAINER_PORT="$2" + shift 2 + ;; *) break ;; @@ -621,8 +628,8 @@ case "$COMMAND" in # additional parameters, such as resource limits, to docker # when launching the weave container. CONTAINER=$(docker run --privileged -d --name=$CONTAINER_NAME \ - -p $PORT:$PORT/tcp -p $PORT:$PORT/udp -e WEAVE_PASSWORD \ - $WEAVE_DOCKER_ARGS $IMAGE -iface $CONTAINER_IFNAME -name $MACADDR -nickname "$NICKNAME" "$@") + -p $PORT:$CONTAINER_PORT/tcp -p $PORT:$CONTAINER_PORT/udp -e WEAVE_PASSWORD \ + $WEAVE_DOCKER_ARGS $IMAGE -iface $CONTAINER_IFNAME -port $CONTAINER_PORT -name $MACADDR -nickname "$NICKNAME" "$@") with_container_netns $CONTAINER launch >/dev/null wait_for_status $CONTAINER_NAME $HTTP_PORT echo $CONTAINER