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.