我有多个服务在docker容器中运行,一个nginx服务器在它们前面,所有容器都在同一个docker网络中。在docker 1.10之前,我创建了一个dnsmasq容器并在nginx中设置了解析器,以便可以从nginx中发现我的服务。
但升级到docker 1.10.1后,dnsmasq图像无效。经过一些研究,我尝试使用地址127.0.0.11中的新“嵌入式dns”(我认为这应该是在docker网络中使用的正确方法)。虽然我可以从nginx容器ping到服务容器,但是nginx继续发回could not be resolved (3: Host not found)
。
然后我尝试使用host命令,我得到了非常令人困惑的结果:(第一个ip地址,然后找不到主机 - 与我从nginx获得的代码相同)
# host service-ui
service-ui has address 172.18.0.7
Host service-ui not found: 3(NXDOMAIN)
Host service-ui not found: 3(NXDOMAIN)
Ping工作
/# ping service-ui
PING service-ui (172.18.0.7): 56 data bytes
64 bytes from 172.18.0.7: icmp_seq=0 ttl=64 time=1.123 ms
64 bytes from 172.18.0.7: icmp_seq=1 ttl=64 time=0.131 ms
64 bytes from 172.18.0.7: icmp_seq=2 ttl=64 time=0.178 ms
以下是我的配置的简化版本:
搬运工-compose.yml
version: '2'
services:
nginx:
build: .
ports:
- 80:80
service-ui:
image: service-ui
networks:
default:
external:
name: ssx
容器中的nginx.conf
location ~ /([a-z]*)/ {
resolver 127.0.0.11;
proxy_pass http://$1-ui:9000$uri$is_args$args;
}
以下是来自主持人的详细结果:
# host -v service-ui
Trying "service-ui"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55237
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;service-ui. IN A
;; ANSWER SECTION:
service-ui. 1800 IN A 172.18.0.7
Received 52 bytes from 127.0.0.11#53 in 1 ms
Trying "service-ui"
Host service-ui not found: 3(NXDOMAIN)
Received 102 bytes from 127.0.0.11#53 in 1 ms
Received 102 bytes from 127.0.0.11#53 in 1 ms
Trying "service-ui"
Host service-ui not found: 3(NXDOMAIN)
Received 102 bytes from 127.0.0.11#53 in 1 ms
Received 102 bytes from 127.0.0.11#53 in 1 ms
我的码头版
Client:
Version: 1.10.1
API version: 1.22
Go version: go1.5.3
Git commit: 9e83765
Built: Thu Feb 11 19:27:08 2016
OS/Arch: linux/amd64
Server:
Version: 1.10.1
API version: 1.22
Go version: go1.5.3
Git commit: 9e83765
Built: Thu Feb 11 19:27:08 2016
OS/Arch: linux/amd64
任何人都可以帮我弄清楚出了什么问题吗?或者如何深入研究这个问题?
答案 0 :(得分:12)
这是因为docker dns服务器不执行ipv6,但是从1.5.8开始,nginx解析器同时查询ipv6和ipv4:http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
你可以在nginx的解析器行上轻松禁用ipv6(参见上面的链接,它只是ipv6 = off)然后它应该开始为你工作。