Nginx无法从docker 1.10.1中的嵌入式DNS获取主机

前端之家收集整理的这篇文章主要介绍了Nginx无法从docker 1.10.1中的嵌入式DNS获取主机前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有几个服务在docker容器中运行,一个Nginx服务器在它们前面,所有容器都在同一个docker网络中.在docker 1.10之前我创建了一个dnsmasq容器并在Nginx中设置了解析器,因此可以从Nginx中发现我的服务.

升级到docker 1.10.1后,dnsmasq映像不起作用.经过一些研究,我尝试使用地址127.0.0.11中的新“嵌入式dns”(我认为这应该是在docker网络中使用的正确方法).虽然我可以从Nginx容器ping到服务容器,但是Nginx继续发送回来无法解决(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

谁能帮我弄清楚出了什么问题?或者如何深入研究这个问题?

最佳答案
这是因为docker dns服务器不执行ipv6,但是从1.5.8:http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver开始,Nginx解析器同时查询ipv6和ipv4

您可以在Nginx中的解析器行上轻松禁用ipv6(参见上面的链接,它只是ipv6 = off)然后它应该开始为你工作.

猜你在找的Nginx相关文章