简体   繁体   English

无法对“外部” DNS服务器进行任何DNS查找?

[英]Can't make any DNS lookups to “external” DNS servers?

I'm trying to fix a bug in my Docker stack for the past few weeks now but to no avail. 我试图在过去的几周内修复Docker堆栈中的错误,但无济于事。

This is the compose file in question (stripped down to the relevant stuff): 这是有问题的撰写文件(深入到相关内容):

version: '3.7'
services:
  php:
    ...
    dns:
      - 1.1.1.1
      - 1.0.0.1
networks:
  default:
    internal: true
      driver: overlay

It deploys just fine until I have to do anything that is requires an "external" DNS request. 它可以很好地部署,直到我必须执行任何需要“外部” DNS请求的操作为止。
Eg. 例如。 in my container I manually run curl https://www.google.com . 在我的容器中,我手动运行curl https://www.google.com
This results in the following error 这导致以下错误

curl: (6) Could not resolve host: google.com curl:(6)无法解析主机:google.com

This is the content of my /etc/resolv.conf inside the container: 这是容器中我的/etc/resolv.conf的内容:

search finlaydag33k.nl
nameserver 127.0.0.11
options ndots:0

Running docker inspect -f '{{.HostConfig.DNS}}' container-id results in the following output: 运行docker inspect -f '{{.HostConfig.DNS}}' container-id会得到以下输出:

[1.1.1.1 1.0.0.1] [1.1.1.1 1.0.0.1]

My question is, what am I doing wrong and how can I fix this? 我的问题是,我在做什么错,我该如何解决? It can reach services within the same stack by dns name just fine, just not domains that require and external DNS (like 1.1.1.1 or 8.8.8.8 ). 它可以通过dns名称到达同一堆栈内的服务,而不能到达需要和外部DNS的域(例如1.1.1.18.8.8.8 )。 Nothing is beeing blocked by my firewall. 我的防火墙没有阻止任何东西。

Try adding a DNS forwarder to '/etc/resolv.conf' by adding 尝试通过添加将DNS转发器添加到“ /etc/resolv.conf”

  server=8.8.8.8
  server=1.1.1.1

See if curl is now resolving google after you have added this 添加此功能后,看看curl是否正在解析google

This is a bit of a "doh" moment. 这是一个“ doh”时刻。
Apparently (though I could not find this in the docs), a container is only hooked up to the default network, which is an overlay network. 显然(尽管我在文档中找不到),但是容器仅连接到default网络,即overlay网络。
This means that one has to explicitly add a bridge network (one should already be present on your swarm) to this container (and also explicitly hook it to the default network so it can communicate with other containers in the stack). 这意味着必须向该容器显式添加一个bridge网络(在您的群集中应该已经存在一个bridge网络)(并且还必须将其显式连接到default网络,以便它可以与堆栈中的其他容器进行通信)。

This was not documented so I assumed it was able to reach the outside already. 这没有记录,所以我认为它已经可以到达外部。
After manually adding the default and bridge networks to the container, everything works as expected. 手动将default网络和bridge网络添加到容器后,一切都会按预期进行。

version: '3.7'
services:
  php:
    ...
    networks:
      - default
      - bridge
    dns:
      - 1.1.1.1
      - 1.0.0.1
networks:
  default:
    internal: true
      driver: overlay
  bridge:
    external: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM