Docker Network Nginx Resolver

前端 未结 6 1593
挽巷
挽巷 2020-11-30 23:49

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

相关标签:
6条回答
  • 2020-12-01 00:19

    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/

    0 讨论(0)
  • 2020-12-01 00:35

    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.

    0 讨论(0)
  • 2020-12-01 00:36

    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

    0 讨论(0)
  • 2020-12-01 00:38

    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:

    1. 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)

    2. 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...

    0 讨论(0)
  • 2020-12-01 00:38

    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;

    0 讨论(0)
  • 2020-12-01 00:42

    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.

    0 讨论(0)
提交回复
热议问题