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 recrea
I solved this problem with the following way:
docker run --rm -d --network host --name "my_domain" nginx
https://docs.docker.com/network/network-tutorial-host/
We hit this with docker containers on windows trying to lookup host.docker.internal using the docker internal resolver at 172.0.0.11. All queries would resolve correctly except host.docker.internal. Fix was to add the ipv6=off flag to the resolver line in nginx.conf.
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 Rancher
First 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:
http {
resolver 127.0.0.11 ipv6=off;
}
This is probably no longer a problem with Docker 1.11:
Fix to not forward docker domain IPv6 queries to external servers (#21396)
Take care that you don't accidentally override the resolver
configuration directive. In my case I had in the server
block resolver 8.8.8.8 8.8.4.4;
from Mozilla's SSL Configuration Generator, which was overriding the resolver 127.0.0.11;
in the http
block. That had me scratching my head for a long time...
In several cases where I had this error, adding resolver_timeout 1s;
to the Nginx config solved the issue. Most of the time I don't have a resolver
entry.
Edit: what also worked for containers where I could explicitly define a nameserver: resolver DNS-IP valid=1s;
You need a local dns server like dnsmasq
to resolve using 127.0.0.1. Try installing it using apk add --update dnsmasq
and set it up if you're using an alpine (nginx:alpine
) variant.