我有几个服务在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)
。
然后我尝试使用主机命令,我得到了非常混乱的结果:(第一个 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 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
以下是我的配置的简化版本:
docker-compose.yml
version: '2'
services:
nginx:
build: .
ports:
- 80:80
service-ui:
image: service-ui
networks:
default:
external:
name: ssx
nginx.conf in container
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
谁能帮我弄清楚出了什么问题?或者如何深入研究这个问题?
这是因为docker dns服务器不执行ipv6,但nginx解析器从1.5.8开始查询IPv6和IPv4: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
您可以在nginx的解析器行上轻松禁用ipv6(请参阅上面的链接,它只是ipv6 = off),然后它应该开始为您工作。