我正在尝试使用.local域访问网络上的设备,但在Docker中似乎无法使用。
来自主机的Ping正在工作:
$ ping test1.local
PING test1.local (192.168.1.90) 56(84) bytes of data.
64 bytes from 192.168.1.90 (192.168.1.90): icmp_seq=1 ttl=255 time=1.41 ms
64 bytes from 192.168.1.90 (192.168.1.90): icmp_seq=2 ttl=255 time=1.54 ms
Docker恶魔配置:
$ cat /etc/docker/daemon.json
{
"dns": ["192.168.1.1","8.8.8.8"]
}
如果我尝试从Docker ping test1.local:
$ sudo docker run --network host busybox ping -c 3 test1.local
ping: bad address 'test1.local'
具有IP功能的Ping设备:
$ sudo docker run --network host busybox ping -c 3 192.168.1.90
PING 192.168.1.90 (192.168.1.90): 56 data bytes
64 bytes from 192.168.1.90: seq=0 ttl=255 time=4.855 ms
64 bytes from 192.168.1.90: seq=1 ttl=255 time=1.566 ms
所以我认为名称解析错误。
madrian@ubuntudev:~$ cat /etc/resolv.conf
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.1
search localdomain
有什么办法解决此问题吗?
答案 0 :(得分:0)
尝试运行您的代码不 --network host
参数。问题出在DNS解析中。
当您使用default bridge
(如果省略network
参数时将使用)时,容器将从主机继承DNS配置,这就是您所需要的:
https://docs.docker.com/v17.09/engine/userguide/networking/default_network/configure-dns/
当您使用user-defined bridge
时,Docker将更新DNS记录,以按其名称启用容器之间的无缝通信:
https://docs.docker.com/v17.09/engine/userguide/networking/configure-dns/
不幸的是,我无法找到有关DNS如何在host
模式下工作的明确解释,所以我认为这是一个问题