From 42f0cb883ae06394ced6ed8d4d92c9c1d820c183 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 24 Nov 2014 20:14:01 +0000 Subject: [PATCH 1/4] Add --with-dns option to weave run --- weave | 41 ++++++++++++++++++++++++++--------------- weavedns/README.md | 13 +++++++------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/weave b/weave index a3865eba..70a56456 100755 --- a/weave +++ b/weave @@ -6,7 +6,7 @@ usage() { echo "weave launch [-password ] ..." echo "weave launch-dns " echo "weave connect " - echo "weave run ..." + echo "weave run [-with-dns] ..." echo "weave start " echo "weave attach " echo "weave detach " @@ -402,21 +402,32 @@ case "$COMMAND" in docker images --no-trunc | grep $DOCKERIMAGE | grep -v latest | tr -s ' ' | cut -d ' ' -f 2 ;; run) - [ $# -gt 0 ] || usage - validate_cidr $1 - CIDR=$1 - shift 1 + [ $# -gt 1 ] || usage create_bridge - DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true - DNS_SEARCH_ARG="--dns-search=." - for arg in $@; do - case $arg in - --dns-search=*) - DNS_SEARCH_ARG="" - ;; - *) - ;; - esac; + for arg in $1 $2; do + case $arg in + [0-9]*) + if [ -z $CIDR ] ; then + validate_cidr $arg + CIDR=$arg + shift 1 + fi + ;; + -with-dns) + shift 1 + DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true + DNS_SEARCH_ARG="--dns-search=." + for arg in $@; do + case $arg in + --dns-search=*) + DNS_SEARCH_ARG="" + ;; + *) + ;; + esac; + done + ;; + esac; done CONTAINER=$(docker run $DNS_ARG $DNS_SEARCH_ARG -d "$@" | tail -n 1) with_container_netns $CONTAINER attach $CIDR >/dev/null diff --git a/weavedns/README.md b/weavedns/README.md index 52714e88..905cd36a 100644 --- a/weavedns/README.md +++ b/weavedns/README.md @@ -8,15 +8,16 @@ the host's configured name server. ## Using weaveDNS -The weave script command `launch-dns` starts the DNS -container. Subsquently, giving any container a hostname in the domain +The weave script command `launch-dns` starts the DNS container, and +then you use the `--with-dns` option on containers you wish to use it. +Subsquently, giving any container a hostname in the domain `.weave.local` will register it in DNS. For example: ```bash $ weave launch $ weave launch-dns 10.1.0.2/16 $ weave run 10.1.1.25/24 -ti -h pingme.weave.local ubuntu -$ shell1=$(weave run 10.1.1.26/24 -ti -h ubuntu.weave.local ubuntu) +$ shell1=$(weave run --with-dns 10.1.1.26/24 -ti -h ubuntu.weave.local ubuntu) $ docker attach $shell1 # ping pingme @@ -39,13 +40,13 @@ If you want to supply other entries for the domain search path, you will need *also* to supply the `weave.local` domain or subdomain: ```bash -weave run 10.1.1.4/24 -ti --dns-search=weave.local --dns-search=local ubuntu +weave run --with-dns 10.1.1.4/24 -ti --dns-search=weave.local --dns-search=local ubuntu ``` ## Doing things more manually -If a weaveDNS container is running, `weave run` will automatically -supply it as the DNS server to the new container. Similarly, both +If you use the `--with-dns` option, `weave run` will automatically +supply the DNS server address to the new container. And both `weave run` and `weave attach` will register the hostname of the given container against the given weave network IP address. From 19f6c17f69e63251d08b648d6f8ca86242ee62da Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 25 Nov 2014 11:01:05 +0000 Subject: [PATCH 2/4] Two minus signs --- weave | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weave b/weave index 70a56456..aa7e6246 100755 --- a/weave +++ b/weave @@ -6,7 +6,7 @@ usage() { echo "weave launch [-password ] ..." echo "weave launch-dns " echo "weave connect " - echo "weave run [-with-dns] ..." + echo "weave run [--with-dns] ..." echo "weave start " echo "weave attach " echo "weave detach " @@ -413,7 +413,7 @@ case "$COMMAND" in shift 1 fi ;; - -with-dns) + --with-dns) shift 1 DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true DNS_SEARCH_ARG="--dns-search=." From 0b051db5e1830d4c36f2fdccdeef18b75f528d05 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 25 Nov 2014 14:09:26 +0000 Subject: [PATCH 3/4] Simplify arg parsing on weave run --- weave | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/weave b/weave index aa7e6246..fa791422 100755 --- a/weave +++ b/weave @@ -403,32 +403,24 @@ case "$COMMAND" in ;; run) [ $# -gt 1 ] || usage + if [ "$1" = "--with-dns" ] ; then + shift 1 + DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true + DNS_SEARCH_ARG="--dns-search=." + for arg in $@; do + case $arg in + --dns-search=*) + DNS_SEARCH_ARG="" + ;; + *) + ;; + esac; + done + fi + validate_cidr $1 + CIDR=$1 + shift 1 create_bridge - for arg in $1 $2; do - case $arg in - [0-9]*) - if [ -z $CIDR ] ; then - validate_cidr $arg - CIDR=$arg - shift 1 - fi - ;; - --with-dns) - shift 1 - DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true - DNS_SEARCH_ARG="--dns-search=." - for arg in $@; do - case $arg in - --dns-search=*) - DNS_SEARCH_ARG="" - ;; - *) - ;; - esac; - done - ;; - esac; - done CONTAINER=$(docker run $DNS_ARG $DNS_SEARCH_ARG -d "$@" | tail -n 1) with_container_netns $CONTAINER attach $CIDR >/dev/null tell_dns PUT $CONTAINER $CIDR From 4046c3a8bcf0d4d3fdb872cfc6ca675d2379582f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 25 Nov 2014 14:13:40 +0000 Subject: [PATCH 4/4] Undid extra check that there is at least one argument to 'docker run' --- weave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave b/weave index fa791422..f0347309 100755 --- a/weave +++ b/weave @@ -402,7 +402,7 @@ case "$COMMAND" in docker images --no-trunc | grep $DOCKERIMAGE | grep -v latest | tr -s ' ' | cut -d ' ' -f 2 ;; run) - [ $# -gt 1 ] || usage + [ $# -gt 0 ] || usage if [ "$1" = "--with-dns" ] ; then shift 1 DNS_ARG=$(docker inspect --format '--dns {{ .NetworkSettings.IPAddress }}'" --link $DNS_CONTAINER_NAME:$DNS_CONTAINER_NAME" $DNS_CONTAINER_NAME 2>/dev/null) || true