I am trying to get rid of deprecated Docker links in my configuration. What's left is getting rid of those Bad Gateway
nginx reverse proxy errors when I recreated a container.
Note: I am using Docker networks in bridge mode. (docker network create nettest
)
I am using the following configuration snippet inside nginx:
location / {
resolver 127.0.0.1 valid=30s;
set $backend "http://confluence:8090";
proxy_pass $backend;
- I started a container with hostname
confluence
on my Docker network with namenettest
. - Then I started the nginx container on network
nettest
. - I can ping
confluence
from inside the nginx container confluence
is listed inside the nginx container's/etc/hosts
file- nginx log says `send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53``
- I tried the docker network default dns resolver
127.0.0.11
from/etc/resol.conf
- nginx log says
confluence could not be resolved (3: Host not found)
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?
Maybe you should check your container's
/etc/resolv.conf
It shows your container's correct DNS config and then use that DNS server IP for resolver.
127.0.0.11
does not works in RancherFirst off, you should be using the Docker embedded DNS server at
127.0.0.11
.Your problem could be caused by 1 of the following:
nginx is trying to use IPv6 (AAAA record) for the DNS queries.
See https://stackoverflow.com/a/35516395/1529493 for the solution.
Basically something like:
This is probably no longer a problem with Docker 1.11:
Take care that you don't accidentally override the
resolver
configuration directive. In my case I had in theserver
blockresolver 8.8.8.8 8.8.4.4;
from Mozilla's SSL Configuration Generator, which was overriding theresolver 127.0.0.11;
in thehttp
block. That had me scratching my head for a long time...You need a local dns server like
dnsmasq
to resolve using 127.0.0.1. Try installing it usingapk add --update dnsmasq
and set it up if you're using an alpine (nginx:alpine
) variant.