【发布时间】:2020-02-10 15:46:38
【问题描述】:
我已经在 AWS 上设置了一个 EC2 实例。
已正确设置我的安全组,以便实例能够访问 Internet,例如
ubuntu@ip-10-17-0-78:/data$ ping www.google.com
PING www.google.com (216.58.211.164) 56(84) bytes of data.
64 bytes from dub08s01-in-f4.1e100.net (216.58.211.164): icmp_seq=1 ttl=46 time=1.02 ms
64 bytes from dub08s01-in-f4.1e100.net (216.58.211.164): icmp_seq=2 ttl=46 time=1.00 ms
但是,当我执行到容器中时,这是不可能的:
root@d1ca5ce50d3b:/app# ping www.google.com
ping: www.google.com: Temporary failure in name resolution
update_1:连接问题与在特定堆栈中使用docker stack deploy 启动的容器有关;
当我刚刚启动一个独立容器时,就可以连接到 Internet:
ubuntu@ip-10-17-0-78:/data$ docker run -it alpine:latest /bin/ash
/ # ping www.google.gr
PING www.google.gr (209.85.203.94): 56 data bytes
64 bytes from 209.85.203.94: seq=0 ttl=38 time=1.148 ms
64 bytes from 209.85.203.94: seq=1 ttl=38 time=1.071 ms
update_2:经过一番调查,事实证明:
- 独立容器,确实继承 EC2 实例的 dns-nameserver;
- 通过
docker stack deploy启动的容器不;
即这是来自docker swarm - 发起的容器:
ubuntu@ip-10-17-0-78:~$ docker exec -it d1ca5ce50d3b bash
root@d1ca5ce50d3b:/app# cat /etc/resolv.conf
search eu-west-1.compute.internal
nameserver 127.0.0.11
options ndots:0
update_3:当我使用docker-compose 而不是docker stack deploy 启动堆栈时,问题也是如此;似乎不是swarm - 具体问题;
update_4:我已经明确添加了gfile /etc/docker/daemon.json,内容如下:
{
"dns": ["10.0.0.2", "8.8.8.8"]
}
ubuntu@ip-10-17-0-78:/data$ docker run busybox nslookup google.com 服务器:8.8.8.8 地址:8.8.8.8:53
非权威答案: 名称:google.com 地址:216.58.211.174
*** 找不到 google.com:没有答案
但查找仍然失败:
有什么建议为什么会发生这种情况?
【问题讨论】:
-
试试
curl而不是ping。