title: Docker Network Nginx Resolver
body: <p>I am trying to get rid of deprecated Docker links in my configuration. What's left is getting rid of those <code>Bad Gateway</code> nginx reverse proxy errors when I recreated a container.</p>
  
  <p>Note: I am using Docker networks in bridge mode. (<code>docker network create nettest</code>)</p>
  
  <p>I am using the following configuration snippet inside nginx:</p>
  
  <pre><code>location / {
        resolver 127.0.0.1 valid=30s;
        set $backend "http://confluence:8090";
        proxy_pass $backend;
  </code></pre>
  
  <ol>
  <li>I started a container with hostname <code>confluence</code> on my Docker network with name <code>nettest</code>. </li>
  <li>Then I started the nginx container on network <code>nettest</code>.</li>
  <li>I can ping <code>confluence</code> from inside the nginx container</li>
  <li><code>confluence</code> is listed inside the nginx container's <code>/etc/hosts</code> file</li>
  <li>nginx log says <code>send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53</code></li>
  <li>I tried the docker network default dns resolver <code>127.0.0.11</code> from <code>/etc/resol.conf</code></li>
  <li>nginx log says <code>confluence could not be resolved (3: Host not found)</code></li>
  </ol>
  
  <p>Anybody knows how to configure nginx resolver with Docker Networks or an alternative on how to force Nginx to correctly resolve the Docker network hostname?</p>