我有多個服務在docker容器中運行,並且在它們前面有一個nginx服務器,同一個docker網絡中的所有容器。在docker 1.10之前,我創建了一個dnsmasq容器,並在nginx中設置瞭解析器,以便我的服務可以從nginx中發現。Nginx無法從Docker中的嵌入式DNS獲取主機1.10.1
但升級到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
以下是我的配置的簡化版本:
泊塢窗,compose.yml
version: '2'
services:
nginx:
build: .
ports:
- 80:80
service-ui:
image: service-ui
networks:
default:
external:
name: ssx
容器
location ~ /([a-z]*)/ {
resolver 127.0.0.11;
proxy_pass http://$1-ui:9000$uri$is_args$args;
}
這裏內nginx.conf也從主機的詳細結果:
# 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
誰能幫我找出什麼不順心?或者如何深入研究這個問題?
謝謝@phobologic,作爲魅力工作 – waterscar
OMG!我一直被困在這個問題上好幾個小時,認爲這是我的nginx配置(我對nginx相當陌生),但實際上你解決了它@phobologic。謝謝你的幫助! – nschoe
Engine 1.11版本現在包含對ipv6的支持。查看博客公告:https://blog.docker.com/2016/04/docker-engine-1-11-runc/ – Subfuzion