/ skydns

Running DNS in docker container

Few lines put together as a reminder on how to set up dns together with etcd in container(s). I will be using skydns and etcd in two separate containers. This is very simple single host docker setup. For more information on skydns and etcd see github:

  1. https://github.com/skynetservices/skydns
  2. https://github.com/coreos/etcd

Getting dns up and running

As mentioned above, the setup is pretty basic. I will be running docker on host with IP 10.37.129.6, docker bridge is on 192.168.1.1/16, and my domain will be *.deki.local

Start up by running etcd with something like this:

#!/bin/bash
HostIP="10.37.129.6" docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs \ -p 4001:4001 \ -p 2380:2380 \ -p 2379:2379 \ --name etcd quay.io/coreos/etcd \ -name etcd0 -advertise-client-urls http://${HostIP}:2379,http://${HostIP}:4001 \ -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \ -initial-advertise-peer-urls http://${HostIP}:2380 \ -listen-peer-urls http://0.0.0.0:2380 \ -initial-cluster-token etcd-cluster-1 \ -initial-cluster etcd0=http://${HostIP}:2380 \ -initial-cluster-state new

At this point we can set up configuration for skydock2 using something like:

#!/bin/bash
curl -XPUT http://10.37.129.6:4001/v2/keys/skydns/config \
-d value='{
"dns_addr":"0.0.0.0:53", \
"pathprefix":"skydns", \
"round_robin":true, \
"domain":"deki.local.", \
"hostmaster":"hm@deki.local", \
"ttl":3600, \
"nameservers": ["8.8.8.8:53","8.8.4.4:53"] \
}'

and start skydock2:

#!/bin/bash
docker run -d -p 10.37.129.6:53:53/udp \
docker.io/skynetservices/skydns \
-machines='http://10.37.129.6:4001' \
-verbose='true'

When containers are up and running we can try and create some dns entries:

curl -XPUT http://10.37.129.6:4001/v2/keys/skydns/local/deki/db1-service/db1 \
-d value='{"host":"191.168.102.121","port":8080}'

and test to see it does work:

dig @10.37.129.6 db1.db1-service.deki.local

Next stop, get skydock running, creating dns entries for containers as they start, and remove them when they exit (or end up killed).

Running DNS in docker container
Share this