title: Make the DNS server of docker container another docker container running DNSmasq
body: <p>I have a set of docker containers created with <code>docker compose</code>, which creates a "user-defined" bridge network.</p>
  
  <p>One of these docker containers is running <a href="https://github.com/jpillora/docker-dnsmasq" rel="nofollow noreferrer">DNSmasq</a> so we can define custom (internal) domain names to point to local IPs.</p>
  
  <p>Trouble is, none of the other docker containers can resolve these domain names. I think the issue is that I can't get the docker DNS to forward its requests to the docker container running DNSmasq (i.e. it doesn't even know it exists).</p>
  
  <p>As a test, I did a <code>docker network inspect &lt;network created by docker compose&gt;</code> and noted the IP address of the DNSmasq container. Then, in one of the other containers' <code>/etc/resolv.conf</code>, I set <code>nameserver</code> to that IP address. Then I can resolve all these internal domains names.</p>
  
  <p>Sadly, putting <code>dnsmasq</code> in there doesn't work, despite the fact that the user-defined network has automatic service discovery enabled.</p>
  
  <p>It seems that one way to make this work then is to force my DNSmasq container to always have the same IP, and then make sure the other docker containers point to that as their nameserver, e.g. by <a href="https://blog.alejandrocelaya.com/2017/04/21/set-specific-ip-addresses-to-docker-containers-created-with-docker-compose/" rel="nofollow noreferrer">defining the network explicitly in the compose file</a>.</p>
  
  <p>Is there no other way? I'd rather not have to define the entire network to replicate this automatically created one when all I want is to know the IP address of one container.</p>