无法smtp.office365.com在Docker用户定义的网桥网络中解析特定主机名(www.example.com

iugsix8n  于 2023-01-08  发布在  Docker
关注(0)|答案(1)|浏览(139)

对于一些带有nslookup的docker映像(例如,我将使用tutum/dnsutils),如果我尝试使用以下命令:

docker run -it --rm tutum/dnsutils nslookup smtp.office365.com

它返回:

Server:         172.25.32.1
Address:        172.25.32.1#53

Non-authoritative answer:
smtp.office365.com      canonical name = outlook.office365.com.
outlook.office365.com   canonical name = outlook.ha.office365.com.
outlook.ha.office365.com        canonical name = outlook.ms-acdc.office.com.
outlook.ms-acdc.office.com      canonical name = ITM-efz.ms-acdc.office.com.
Name:   ITM-efz.ms-acdc.office.com
Address: 40.99.9.18
...

然后,我通过运行docker network create testnet创建一个网络,并尝试以下命令:

docker run -it --rm --net testnet tutum/dnsutils nslookup smtp.office365.com

它返回:

Server:         127.0.0.11
Address:        127.0.0.11#53

Non-authoritative answer:
*** Can't find smtp.office365.com: No answer

为什么会有这样的差别呢?
如果我对主机outlook.office365.com尝试这些命令,两者都成功地返回解析的ip地址。
我在WSL中使用Docker的以下版本:

$docker version

Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:01:58 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 17:59:49 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.12
  GitCommit:        a05d175400b1145e5e6a735a6710579d181e7fb0
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
oxiaedzo

oxiaedzo1#

这是网桥网络的默认行为:
默认情况下,来自连接到默认网桥网络的container的流量不会转发到外部世界。
请参考此处的正式文档启用转发。

相关问题