From 108eea8b79e241aba9d828a01c9279eeb55aa93b Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 10 Jun 2015 16:42:59 +0100 Subject: [PATCH] Modify `weave run` to use container name as fqdn When run is invoked with `--with-dns` and a container name but no hostname, synthesise a fully qualified hostname from the container name and the weaveDNS domain and supply that as a hostname for the container. --- weave | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/weave b/weave index 4b1aeee0..9a5f8f08 100755 --- a/weave +++ b/weave @@ -648,25 +648,34 @@ dns_args() { docker_bridge_ip DNS_ARG="--dns $DOCKER_BRIDGE_IP" DNS_SEARCH_ARG="--dns-search=." + HOSTNAME_ARG="" + HOSTNAME_SPECIFIED=false for arg in "$@" ; do case $arg in --dns-search=*) DNS_SEARCH_ARG="" ;; - *) + --name=*) + HOSTNAME_ARG="--hostname=${arg#--name=}.$(dns_domain)" + ;; + -h|--hostname=*) + HOSTNAME_SPECIFIED=true ;; esac done - DNS_ARGS="$DNS_ARG $DNS_SEARCH_ARG" + if [ "$HOSTNAME_SPECIFIED" = "true" ] ; then + HOSTNAME_ARG="" + fi + DNS_ARGS="$DNS_ARG $DNS_SEARCH_ARG $HOSTNAME_ARG" } # Use the weaveDNS REST API to determine the local domain. If weaveDNS is not -# running, return the default value ('weave.local.') +# running, return the default value ('weave.local') dns_domain() { if DOMAIN=$(http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /domain 2>/dev/null) ; then - echo $DOMAIN + echo ${DOMAIN%.} else - echo 'weave.local.' + echo 'weave.local' fi }