尝试使用Resolv::DNS
解析MX记录时遇到问题。当我在irb
中直接在我的Mac上执行以下行时,一切正常:
> require "resolv"
> Resolv::DNS.new.getresource("stackoverflow.com", Resolv::DNS::Resource::IN::MX)
=> #<Resolv::DNS::Resource::IN::MX:0x00007fba42812ff0 @preference=10, @exchange=#<Resolv::DNS::Name: alt4.aspmx.l.google.com.>, @ttl=243>
在docker容器内执行的同一行返回错误:
> require "resolv"
> Resolv::DNS.new.getresource("stackoverflow.com", Resolv::DNS::Resource::IN::MX)
Resolv::ResolvError: DNS result has no information for stackoverflow.com
from /usr/local/lib/ruby/2.4.0/resolv.rb:492:in `getresource'
我认为问题是docker-machine
。我使用以下配置运行了dinghy 4.6.3(请参阅https://github.com/codekitchen/dinghy)配置的docker-machine
:
Boot2Docker version 18.01.0-ce, build HEAD : 0bb7bbd - Thu Jan 11 16:32:39 UTC 2018
Docker version 18.01.0-ce, build 03596f5
docker@dinghy:~$ busybox | head -1
BusyBox v1.27.2 (2017-10-30 14:58:40 UTC) multi-call binary.
我的docker容器基于ruby:2.4.3-stretch
。
我不确定resolv.conf
docker@dinghy:~$ cat /etc/resolv.conf
nameserver 10.0.2.3
配置是否足以进行mx查找?
更新
这是来自容器内的dig
响应(不是来自docker-machine本身,不幸的是,dig包没有随busybox一起提供):
root@3ef2090b7864:/usr/src/app# dig @10.0.2.3 MX stackoverflow.com
; <<>> DiG 9.10.3-P4-Debian <<>> @10.0.2.3 MX stackoverflow.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOTIMP, id: 32375
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;stackoverflow.com. IN MX
;; Query time: 0 msec
;; SERVER: 10.0.2.3#53(10.0.2.3)
;; WHEN: Tue Apr 03 14:29:30 CEST 2018
;; MSG SIZE rcvd: 46