gpt4 book ai didi

networking - 有时 docker 容器 dns 失败

转载 作者:行者123 更新时间:2023-12-04 19:31:14 25 4
gpt4 key购买 nike

有时我的 docker 容器无法解析 dns..

[root@1397f4b5b0b8 ~]# ping google.co.kr
ping: unknown host google.co.kr

虽然一周后它可以正常工作。突然间它引起了问题。

一些信息。

1) docker容器ip

160: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 16:a4:72:e5:a0:a4 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.4/16 scope global eth0
inet6 fe80::14a4:72ff:fee5:a0a4/64 scope link
valid_lft forever preferred_lft forever
162: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever

2) docker 容器结果.conf

options timeout:1 attempts:1 rotate
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 192.168.100.60

3) 我向另一个容器发送了 ping

[root@1397f4b5b0b8 ~]# ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=1.01 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.060 ms
64 bytes from 172.17.0.3: icmp_seq=3 ttl=64 time=0.033 ms

4) docker 地址

docker0   Link encap:Ethernet  HWaddr FE:4D:B5:ED:F2:9C  
inet addr:172.17.42.1 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::fc99:12ff:fe49:b968/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10615013037 errors:0 dropped:0 overruns:0 frame:0
TX packets:10581841163 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1452195292535 (1.3 TiB) TX bytes:1436185782855 (1.3 TiB)

em1 Link encap:Ethernet HWaddr C8:1F:66:F9:22:1B
inet addr:192.168.100.64 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::ca1f:66ff:fef9:221b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:18816069331 errors:0 dropped:4421 overruns:0 frame:69216
TX packets:18985345996 errors:0 dropped:6 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2823201130099 (2.5 TiB) TX bytes:2383729440082 (2.1 TiB)
Interrupt:35

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:14689636131 errors:0 dropped:0 overruns:0 frame:0
TX packets:14689636131 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1541592592181 (1.4 TiB) TX bytes:1541592592181 (1.4 TiB)

5)docker路由表

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 em1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
0.0.0.0 192.168.100.1 0.0.0.0 UG 0 0 0 em1

我重新启动 docker 并启动容器。然后docker容器就可以连接到外部了。

[root@1397f4b5b0b8 ~]# ping google.co.kr
PING google.co.kr (173.194.72.94) 56(84) bytes of data.
64 bytes from tf-in-f94.1e100.net (173.194.72.94): icmp_seq=1 ttl=48 time=69.3 ms
64 bytes from tf-in-f94.1e100.net (173.194.72.94): icmp_seq=2 ttl=48 time=69.4 ms
64 bytes from tf-in-f94.1e100.net (173.194.72.94): icmp_seq=3 ttl=48 time=69.4 ms
64 bytes from tf-in-f94.1e100.net (173.194.72.94): icmp_seq=4 ttl=48 time=69.3 ms

我该如何解决?

最佳答案

由于某些原因,resolv.conf 权限太受限制。您可以通过以下方式解决:

sudo chmod 644 /etc/resolv.conf

关于networking - 有时 docker 容器 dns 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28144462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com