From b84a3d01614daaf4b553f33256b0b1d6cb0cb482 Mon Sep 17 00:00:00 2001 From: Rachid Zarouali Date: Wed, 13 Jan 2016 10:25:20 +0100 Subject: [PATCH 1/5] initial factorisation of dns-discovery service --- Dockerfile | 3 ++- entrypoint.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8fdf1cc..1dda27c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,8 @@ COPY conf/supervisord.conf /etc/supervisor.d/docker-gen.ini COPY entrypoint.sh /opt/entrypoint.sh # Default IP for Drude -ENV DRUDE_IP '192.168.10.10' +ENV DNS_IP '192.168.10.10' +ENV DNS_ZONE 'localzone' ENV LOG_QUERIES false ENV DOCKER_HOST unix:///var/run/docker.sock diff --git a/entrypoint.sh b/entrypoint.sh index b3ba95d..e64c521 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,12 +3,12 @@ set -e # Default command (assuming container start) if [ "$1" = 'supervisord' ]; then - # Drude IP config for dnsmasq - touch /etc/dnsmasq.d/drude.conf - # Resolve *.drude to $DRUDE_IP - echo "address=/drude/${DRUDE_IP}" >> /etc/dnsmasq.d/drude.conf - # Reverse resolution of $DRUDE_IP to 'drude' - echo $DRUDE_IP | awk -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,drude"}' >> /etc/dnsmasq.d/drude.conf + # $DNS_ZONE IP config for dnsmasq + touch /etc/dnsmasq.d/${DNS_ZONE}.conf + # Resolve *.$DNS_ZONE to $DNS_IP + echo "address=/${DNS_ZONE}/${DNS_IP}" >> /etc/dnsmasq.d/${DNS_ZONE}.conf + # Reverse resolution of $DNS_IP to ${DNS_ZONE} + echo $DNS_IP | awk -v dzone=${DNS_ZONE} -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,"dzone}' >> /etc/dnsmasq.d/${DNS_ZONE}.conf # Turn query loggin on if [ "$LOG_QUERIES" = true ]; then From b8f999db707cd58fc9a9facbefc03e0ccd2e466f Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Tue, 12 Jul 2016 12:22:44 -0800 Subject: [PATCH 2/5] Version updates and minor refactoring - alpine 3.4 - docker-gen 0.7.3 - use `--no-cache` option with apk - remove DOCKER_HOST env variable and /var/run volume --- Dockerfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9dd1d5c..25dc52a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,19 @@ -FROM alpine:3.3 +FROM alpine:3.4 MAINTAINER Leonid Makarov -RUN apk add --update \ - ca-certificates \ +RUN apk add --no-cache \ + curl \ supervisor \ dnsmasq \ - && rm -rf /var/cache/apk/* # Install docker-gen -ENV DOCKER_GEN_VERSION 0.7.1 -RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz && \ - tar -C /usr/local/bin -xvzf docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz && \ - rm /docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz +ENV DOCKER_GEN_VERSION 0.7.3 +ENV DOCKER_GEN_TARFILE docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz +RUN curl -sSL https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/$DOCKER_GEN_TARFILE -O && \ + tar -C /usr/local/bin -xvzf $DOCKER_GEN_TARFILE && \ + rm $DOCKER_GEN_TARFILE # dnsmasq config dir RUN mkdir -p /etc/dnsmasq.d && \ @@ -26,9 +26,7 @@ COPY entrypoint.sh /opt/entrypoint.sh # Default IP for Drude ENV DRUDE_IP '192.168.10.10' ENV LOG_QUERIES false -ENV DOCKER_HOST unix:///var/run/docker.sock -VOLUME /var/run EXPOSE 53/udp ENTRYPOINT ["/opt/entrypoint.sh"] From 5c5a8eb794d827bcd5d175d078bfeb40f3296f77 Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Fri, 9 Sep 2016 16:44:25 -0700 Subject: [PATCH 3/5] dnsgen template update \nSimplification and support for v2 networking --- conf/dnsmasq.tmpl | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/conf/dnsmasq.tmpl b/conf/dnsmasq.tmpl index a403846..5d3787e 100644 --- a/conf/dnsmasq.tmpl +++ b/conf/dnsmasq.tmpl @@ -1,19 +1,9 @@ {{ range $host, $containers := groupByMulti $ "Env.DOMAIN_NAME" "," }} {{ range $index, $container := $containers }} - {{ $addrLen := len $container.Addresses }} - {{ $address := $container }} - {{ if gt $addrLen 0 }} - {{ $address := index $container.Addresses 0 }} + {{ range $index, $network := $container.Networks }} + {{ if ne $network.IP "" }} +address=/{{ $host }}/{{ $network.IP }} + {{ end }} {{ end }} -address=/{{ $host }}/{{ $address.IP }} {{ end }} {{ end }} - -{{ range $index, $container := $ }} - {{ $addrLen := len $container.Addresses }} - {{ $address := $container }} - {{ if gt $addrLen 0 }} - {{ $address := index $container.Addresses 0 }} - {{ end }} -address=/{{ $container.Name }}.docker/{{ $address.IP }} -{{ end }} From fa7492040161583622ef4bb2997358dff093e966 Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Fri, 9 Sep 2016 17:05:27 -0700 Subject: [PATCH 4/5] Configuration via both env variable (DNS_NAME) and label (dns.name) --- conf/dnsmasq.tmpl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/conf/dnsmasq.tmpl b/conf/dnsmasq.tmpl index 5d3787e..481b0d6 100644 --- a/conf/dnsmasq.tmpl +++ b/conf/dnsmasq.tmpl @@ -1,9 +1,24 @@ -{{ range $host, $containers := groupByMulti $ "Env.DOMAIN_NAME" "," }} - {{ range $index, $container := $containers }} - {{ range $index, $network := $container.Networks }} - {{ if ne $network.IP "" }} +{{/* template */}} +{{ define "host" }} + {{ $host := .Host }} + {{ range $index, $network := .Container.Networks }} + {{ if ne $network.IP "" }} address=/{{ $host }}/{{ $network.IP }} - {{ end }} {{ end }} {{ end }} {{ end }} + +{{/* Configuration via "dns.name" label */}} +{{ range $index, $container := (whereLabelExists . "dns.name") }} + {{ with $container }} + {{ $dnsname := index .Labels "dns.name" }} + {{ template "host" (dict "Container" $container "Host" (print $dnsname) "Tld" "") }} + {{ end }} +{{ end }} + +{{/* Configuration via "DNS_NAME" envitonment variables */}} +{{ range $host, $containers := groupByMulti $ "Env.DNS_NAME" "," }} + {{ range $index, $container := $containers }} + {{ template "host" (dict "Container" $container "Host" (print $host) "Tld" "") }} + {{ end }} +{{ end }} From ee3f515fadbc621eccaeb3f324dbf0c32dd793eb Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Tue, 11 Oct 2016 17:50:14 -0700 Subject: [PATCH 5/5] Updates for Docksal --- Dockerfile | 8 ++++---- entrypoint.sh | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6462aa5..c2f7f62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.4 -MAINTAINER Leonid Makarov +MAINTAINER Leonid Makarov RUN apk add --no-cache \ curl \ @@ -23,9 +23,9 @@ COPY conf/dnsmasq.tmpl /etc/dnsmasq.d/dockergen.tmpl COPY conf/supervisord.conf /etc/supervisor.d/docker-gen.ini COPY entrypoint.sh /opt/entrypoint.sh -# Default IP for Drude -ENV DNS_IP '192.168.10.10' -ENV DNS_ZONE 'localzone' +# Default domain and IP for wildcard query resolution +ENV DNS_DOMAIN 'docksal' +ENV DNS_IP '192.168.64.100' ENV LOG_QUERIES false EXPOSE 53/udp diff --git a/entrypoint.sh b/entrypoint.sh index e64c521..809f793 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,12 +3,12 @@ set -e # Default command (assuming container start) if [ "$1" = 'supervisord' ]; then - # $DNS_ZONE IP config for dnsmasq - touch /etc/dnsmasq.d/${DNS_ZONE}.conf - # Resolve *.$DNS_ZONE to $DNS_IP - echo "address=/${DNS_ZONE}/${DNS_IP}" >> /etc/dnsmasq.d/${DNS_ZONE}.conf - # Reverse resolution of $DNS_IP to ${DNS_ZONE} - echo $DNS_IP | awk -v dzone=${DNS_ZONE} -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,"dzone}' >> /etc/dnsmasq.d/${DNS_ZONE}.conf + # $DNS_DOMAIN IP config for dnsmasq + touch /etc/dnsmasq.d/${DNS_DOMAIN}.conf + # Resolve *.$DNS_DOMAIN to $DNS_IP + echo "address=/${DNS_DOMAIN}/${IP}" >> /etc/dnsmasq.d/${DNS_DOMAIN}.conf + # Reverse resolution of $DNS_IP to ${DNS_DOMAIN} + echo $DNS_IP | awk -v dzone=${DNS_DOMAIN} -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,"dzone}' >> /etc/dnsmasq.d/${DNS_DOMAIN}.conf # Turn query loggin on if [ "$LOG_QUERIES" = true ]; then