title: How to debug DNS not working for Docker Container?
body: <p>I am beginning to work with Docker containers and have a problem with DNS resolution from a container.
  There seem to be many questions on StackOverflow similar to this problem, but I'm not able to solve it.</p>
  
  <p>I'm on CentOS Linux 7.7.1908 Host.
  I've built a new container on this machine and and add it to an existing docker-compose.yml file.</p>
  
  <p>But something seems to be missing in my container -- DNS isn't working within it.
  Other containers started from docker-compose don't have this problem.</p>
  
  <p>In docker-compose, the start of my new container and a DNS-working existing container seem the same, something like the following:</p>
  
  <pre><code>existingcontainer:
      image: johnson/job1:2.1.0
      environment:
          JAVA_OPTS: " -Xms256m -Xmx512m"
      ports:
          - 8090:8090
  
  newcontainer:
      image: johnson/job2:1.0.0
      environment:
          JAVA_OPTS: " -Xms256m -Xmx512m"
      ports:
          - 8091:8090
  </code></pre>
  
  <p>The containers start up and the functionality within them both work fine, except within the new container DNS doesn't work.</p>
  
  <pre><code>docker container exec existingcontainer_1 ping google.com
  PING google.com (172.217.12.238) 56(84) bytes of data.
  ...
  
  docker container exec newcontainer_1 ping google.com
  ping: google.com: Name or service not known
  
  docker container exec newcontainer_1 ping 172.217.12.238
  PING google.com (172.217.12.238) 56(84) bytes of data.
  ...
  </code></pre>
  
  <p>So, DNS resolution isn't working with the newcontainer, but it is possible to access the internet via an IP address.  My conclusion is that some configuration is missing in the container.</p>
  
  <pre><code>docker container exec existingcontainer_1 cat /etc/hosts
  127.0.0.1  localhost
  ::1   localhost ip6-localhost
  fe00::0 ip6-localnet
  ff00::0 ip6-mcastprefix
  ff02::1 ip6-allnodes
  ff02::2 ip6-allrouters
  172.18.0.15  2a51cabe0eaf
  
  docker container exec newcontainer_1 cat /etc/hosts
  127.0.0.1  localhost
  ::1   localhost ip6-localhost
  fe00::0 ip6-localnet
  ff00::0 ip6-mcastprefix
  ff02::1 ip6-allnodes
  ff02::2 ip6-allrouters
  172.18.0.11  0c73f229b689
  
  docker container exec existingcontainer_1 cat /etc/resolv.conf
  search ec2.internal
  nameserver 127.0.0.11
  options ndots::0
  
  docker container exec newcontainer_1 cat /etc/resolv.conf
  search ec2.internal
  nameserver 127.0.0.11
  options ndots::0    
  </code></pre>
  
  <p>The networking configurations for DNS look the same.<br>
  Based on some articles, I added the following ExecStart setting in the docker.service file to force a DNS server and then restarted docker and the docker-compose containers:</p>
  
  <pre><code>--dns 8.8.8.8
  </code></pre>
  
  <p>But I see the same behavior after doing that -- DNS doesn't work on the new container.  Also, since DNS was already working in some containers, but not the new one, so I think the right fix is not a global one like that -- it seems like a change is needed to the new container.</p>
  
  <p>To do troubleshooting on the container, I also found that a number of standard utilities don't seem to be available in the container environment, like netstat and iptables.  I could probably just copy these from the Host to the container?</p>
  
  <p>How best to debug this?</p>