这与下面的question非常相似,但是前一个问题的解决方案/答案并不能解决问题。
在我的例子中,我并没有特别连接到MySQL,但是尝试解析www.google.com只会在容器中产生相同的UnknownHostException。当我只从JVM运行,而不是在我的MAC上的容器中运行时,没有问题需要解决。
场景相同: InetAddress ip = InetAddress.getByName("www.google.com");
我已经尝试了以下建议的修复方法:
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
以及..。
RUN echo "hosts: files dns" >> /etc/nsswitch.conf"
这两个看起来都没成功..
除了上面的建议之外,我还有什么其他的建议吗?
提前谢谢。
发布于 2018-08-12 09:00:56
事实证明,解决方案相当简单,有几个选择。
对于你们专家来说,这可能很有趣,但至少对下一个人来说这是一个新的想法。
因此,我发现我可以通过以下方式指定集群中每个节点上的DNS:
/etc/docker/daemon.json
{
"dns": ["10.0.0.2", "8.8.8.8", etc.. ]
}
在每个节点上设置后,特别是为谷歌的域名系统设置8.8.8.8,然后"google.com“解析,没有探测。请注意,这是一个谷歌特定的DNS,但它提供了一个公共DNS。雅虎,亚马逊等都解决了..10.0.0.2地址可以是您想要指定的任何其他DNS,并且您可以指定倍数。
这来自于下面的帖子:Fix Docker's networking DNS config
然而,如果你想通过你的compose/stack文件指定DNS,那就更容易了。
您可以直接在撰写中指定daemon.json,而不是转到群中的每个节点并更新DNS条目。
version: '3.3'
services:
my-sample-service:
image: my-repo/my-sample:1.0.0
ports: 8081:8080
networks:
- my-network
dns:
- 10.0.0.1 #this would be whatever your say internal DNS is priority 1
- 10.0.0.2 #this would be whatever other DNS you'd provide priority 2
- 8.8.8.8 #default google address, even though docker specifies this
#as a default, it wasn't working until I specifically set it
#this would be the last one checked if no resolution happened
#on the first two.
https://stackoverflow.com/questions/51774204
复制相似问题