title: docker: containers in stacks within EC2 instance do not inherit dns nameserver
body: <p>I have set up an EC2 instance on AWS.</p>
  
  <p>Have set up my security groups properly so that the instance is able to reach the Internet, e.g.</p>
  
  <pre><code>ubuntu@ip-10-17-0-78:/data$ ping www.google.com
  PING www.google.com (216.58.211.164) 56(84) bytes of data.
  64 bytes from dub08s01-in-f4.1e100.net (216.58.211.164): icmp_seq=1 ttl=46 time=1.02 ms
  64 bytes from dub08s01-in-f4.1e100.net (216.58.211.164): icmp_seq=2 ttl=46 time=1.00 ms
  </code></pre>
  
  <p>However, when I exec into a container, this is not possible:</p>
  
  <pre><code>root@d1ca5ce50d3b:/app# ping www.google.com
  ping: www.google.com: Temporary failure in name resolution
  </code></pre>
  
  <p><strong>update_1</strong>: the connectivity issue has to do with containers being initiated with <code>docker stack deploy</code>, in specific stacks;</p>
  
  <p>When I just start a stand-alone container, connectivity to the Internet is there:</p>
  
  <pre><code>ubuntu@ip-10-17-0-78:/data$ docker run -it alpine:latest /bin/ash
  / # ping www.google.gr
  PING www.google.gr (209.85.203.94): 56 data bytes
  64 bytes from 209.85.203.94: seq=0 ttl=38 time=1.148 ms
  64 bytes from 209.85.203.94: seq=1 ttl=38 time=1.071 ms
  </code></pre>
  
  <p><strong>update_2</strong>: After some investigation, it turns out that:</p>
  
  <ul>
  <li>the stand-alone container, <strong>does</strong> inherit the EC2 instance's dns-nameserver;</li>
  <li>the containers started via <code>docker stack deploy</code> do <strong>not</strong>;</li>
  </ul>
  
  <p>i.e. this is from a <code>docker swarm</code> - initiated container:</p>
  
  <pre><code>ubuntu@ip-10-17-0-78:~$ docker exec -it d1ca5ce50d3b bash
  root@d1ca5ce50d3b:/app# cat /etc/resolv.conf 
  search eu-west-1.compute.internal
  nameserver 127.0.0.11
  options ndots:0
  </code></pre>
  
  <p><strong>update_3</strong>: Same is the problem when I start the stack with <code>docker-compose</code> instead of <code>docker stack deploy</code>; does not seem to be a <code>swarm</code> - specific issue;</p>
  
  <p><strong>update_4</strong>: I have explicitly added the gfile <code>/etc/docker/daemon.json</code> with the following contents:</p>
  
  <pre><code>{
      "dns": ["10.0.0.2", "8.8.8.8"]
  }
  </code></pre>
  
  <p>ubuntu@ip-10-17-0-78:/data$ docker run busybox nslookup google.com
  Server:     8.8.8.8
  Address:    8.8.8.8:53</p>
  
  <p>Non-authoritative answer:
  Name:   google.com
  Address: 216.58.211.174</p>
  
  <p>*** Can't find google.com: No answer</p>
  
  <p>but lookup still fails:</p>
  
  <p>Any suggestions why this might be hapenning?</p>