Nginx在docker 1.10.1中没有从嵌入式DNS中获取主机 [英] Nginx doesn't get host from embedded DNS in docker 1.10.1

查看:265
本文介绍了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:主机未找到)



然后我尝试使用主机命令,我得到非常混乱的结果:(第一个ip地址,然后主机找不到 - 与从nginx得到的代码相同) / p>

 #host service-ui 
service-ui有地址172.18.0.7
没有找到主机服务:3(NXDOMAIN)
主机服务 - 未找到:3(NXDOMAIN)

Ping作品

  /#ping service-ui 
PING service-ui(172.18.0.7):56个数据字节
从172.18.0.7的64字节:icmp_seq = 0 ttl = 64时间= 1.123 ms
从172.18.0.7的64字节:icmp_seq = 1 ttl = 64时间= 0.131 ms
从172.18.0.7的64个字节:icmp_seq = 2 ttl = 64 time = 0.178 ms

以下是我的配置的简化版本: / p>

docker-compose.yml

 版本:'2'

服务:
nginx:
build:。
ports:
- 80:80
service-ui:
image:service-ui
networks:
default:
external:
名称:ssx

容器内的nginx.conf

  location〜/([az] *)/ {
resolver 127.0.0.11;
proxy_pass http:// $ 1-ui:9000 $ uri $ is_args $ args;
}

这里还有主持人的详细结果:

 #host -v service-ui 
尝试service-ui
;; - >> HEADER< - opcode:QUERY,status:NOERROR,id:55237
;;标志:qr rd; QUERY:1,ANSWER:1,AUTHORITY:0,ADDITIONAL:0

;;问题部分:
; service-ui。 IN A

;;解答部分:
service-ui。 1800 IN A 172.18.0.7

从127.0.0.11收到52个字节#53 in 1 ms
尝试service-ui
主机服务未找到:3(NXDOMAIN )
从127.0.0.11收到102个字节#53 in 1 ms
从127.0.0.11收到102个字节#1 1 ms
尝试service-ui
主机服务 - 没有找到:3(NXDOMAIN)
从127.0.0.11收到102个字节#53 in 1 ms
从127.0.0.11收到102个字节#53 in 1 ms

我的码头版本

 客户端:
版本:1.10.1
API版本:1.22
Go版本:go1.5.3
Git提交:9e83765
内置:Thu Feb 11 19:27:08 2016
OS / Arch:linux / amd64

服务器:
版本:1.10.1
API版本:1.22
转到版本:go1.5.3
Git提交:9e83765
内置:Thu Feb 11 19:27:08 2016
操作系统/ Arch:linux / amd64

任何人都可以帮我弄清楚出了什么问题?还是如何挖掘这个问题?

解决方案

这是因为docker dns服务器不执行ipv6,但是nginx解析器查询ipv6和ipv4为1.5 .8: http://nginx.org/en/docs/http/ngx_http_core_module。 html#resolver



您可以在nginx的解析器行中轻松关闭ipv6(请参阅上面的链接,它只是ipv6 = off),然后应该开始为你工作。


I have several services running in docker containers, and one nginx server in front of them, all containers within the same docker network. Before docker 1.10 I created a dnsmasq container and within nginx set resolver to it so my services can be discovered from nginx.

But after upgrading to docker 1.10.1, the dnsmasq image doesn't work. After some research, I tried to use the new "embedded dns" from address 127.0.0.11 instead (which I think should be the correct way to use within docker network). Though I can ping to the service container from nginx container, but nginx keep sending back could not be resolved (3: Host not found).

And then I tried to use host command, I got very confusing result: (first ip address, and then host not found - same code as I got from 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 works

/# 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

Following is a simplified version of my configurations:

docker-compose.yml

version: '2'

services:
  nginx:
    build: .
    ports:
      - 80:80   
  service-ui:
    image: service-ui
networks:
  default:
    external:
      name: ssx

nginx.conf within container

 location ~ /([a-z]*)/ {
  resolver 127.0.0.11;
  proxy_pass http://$1-ui:9000$uri$is_args$args;
}

Here's also the verbose result from host:

# 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

My docker version

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

Can anyone help me figure out what goes wrong? Or how to dig into this issue?

解决方案

This is because the docker dns server does not do ipv6, but the nginx resolver queries for both ipv6 and ipv4 as of 1.5.8: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

You can disable ipv6 easily enough on the resolver line in nginx (see the link above, it's just ipv6=off) and then it should start working for you.

这篇关于Nginx在docker 1.10.1中没有从嵌入式DNS中获取主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆