Docker DNS getaddrinfo ENOTFOUND [英] Docker DNS getaddrinfo ENOTFOUND
问题描述
我正在运行docker-compose with node:4.2.1-wheezy
和 dnsdock
containers。
I am running docker-compose with node:4.2.1-wheezy
and dnsdock
containers.
我有$ code> DOCKER_OPTS = - dns 172.17.42.1 in / etc / default / docker。
I have DOCKER_OPTS="--dns 172.17.42.1"
inside /etc/default/docker.
在我的node.js容器内运行 node -erequire('dns')。resolve('host_name_here')
主机通过172.17.42.1 dns服务器正确解析。
When I run node -e "require('dns').resolve('host_name_here')"
inside my node.js container the host is resolved correctly through the 172.17.42.1 dns server.
但是当我运行 node -erequire('dns')。lookup ('host_name_here')
它失败, ENOTFOUND
错误。
But when I run node -e "require('dns').lookup('host_name_here')"
it fails with ENOTFOUND
error.
是 http.request
使用 dns.lookup
而不是 dns.resolve
。
文档说 dns.lookup
调用 getaddrinfo
。而且据我所知 getaddrinfo
缓存/etc/resolv.conf,也许它缓存空/etc/resolv.conf(但$ code> cat / etc / resolv.conf 打印 nameserver 172.17.42.1
)。
The docs say that dns.lookup
calls getaddrinfo
. And as far as I understand getaddrinfo
caches /etc/resolv.conf and maybe it caches empty /etc/resolv.conf (but cat /etc/resolv.conf
prints nameserver 172.17.42.1
).
我真的不知道如何解决这个问题。什么可以导致这种行为?
I really have no idea how to resolve this issue. What can cause such behavior?
更新1。
docker -v
Docker version 1.7.1, build 786b29d
docker-compose -v
docker-compose version: 1.4.2
更新2。
将所有内容更新到最新版本(docker 1.9.0,docker-compose 1.5.0和节点高达5.0.0),但问题仍然存在。
I updated all things to the latest versions (docker 1.9.0, docker-compose 1.5.0 and node up to 5.0.0) but the issue still persists.
所以这是重现问题的docker-compose.yml:
So this is the docker-compose.yml that reproduces the issue:
dnsdock:
image: tonistiigi/dnsdock
volumes:
- /var/run/docker.sock:/run/docker.sock
ports:
- "172.17.42.1:53:53/udp"
environment:
- DNSDOCK_ALIAS=dns.org
node:
image: node:5.0.0-wheezy
command: node -e "setTimeout(function () { var dns = require('dns'); dns.resolve('dns.org', console.log.bind(console, 'resolve')); dns.lookup('dns.org', console.log.bind(console, 'lookup')); }, 5000)"
dns: 172.17.42.1
您应该替换 172.17.42.1
与您的docker0接口的IP,需要 setTimeout(...,5000)
,因为节点
容器可能在 dnsdock
之前开始。
You should replace 172.17.42.1
with IP of your docker0 interface. The setTimeout(..., 5000)
is needed because node
container may start before dnsdock
.
这是我的 docker-compose up
输出:
Creating test_node_1
Creating test_dnsdock_1
Attaching to test_node_1, test_dnsdock_1
dnsdock_1 | 2015/11/07 09:29:44 Added service: 3653951cff40c06c04b9ab3f5d2fc94ccc19305eaac7ba1a545ce1dbab3e3e17 {test_dnsdock_1 dnsdock 172.17.42.3 -1 [dns.org]}
dnsdock_1 | 2015/11/07 09:29:44 Added service: 36577feea136bc713f77b64b2a6a9712cd509c47ca55427f6749308cc5a4b140 {test_node_1 node 172.17.42.2 -1 []}
node_1 | resolve null [ '172.17.42.3' ]
node_1 | lookup { [Error: getaddrinfo ENOTFOUND dns.org]
node_1 | code: 'ENOTFOUND',
node_1 | errno: 'ENOTFOUND',
node_1 | syscall: 'getaddrinfo',
node_1 | hostname: 'dns.org' }
dnsdock_1 | 2015/11/07 09:29:49 Stopped service: 36577feea136bc713f77b64b2a6a9712cd509c47ca55427f6749308cc5a4b140
test_node_1 exited with code 0
推荐答案
为了更好的dns查找,您可以考虑使用网络覆盖,如 Docker覆盖网络:很简单
For a better dns lookup, you could consider using a network overlay, as presented in "Docker Overlay Networks: That was Easy"
它使用KV / Value)存储基于领事馆,和一个群集,您可以在其中注册节点。
It uses a KV (Key/Value) store bases on Consul, and a swarm cluster where you can register your nodes.
您可以构建覆盖网络
eval "$(docker-machine env --swarm c0-master)"
docker network create -d overlay myStack1
并使用它来运行图像:
docker run -d --name web --net myStack1 nginx
docker run -itd --name shell1 --net myStack1 alpine /bin/sh
容器将被附加到同一个网络,并且可以通过容器名称(不管启动顺序)来发现。
此外,当容器重新启动时,它将保持可被发现,而不必重新启动。
Both of these containers will be attached to the same network, and be discoverable by container name (regardless of start order).
Further, when a container is restarted it will remain discoverable without cascading restarts.
这篇关于Docker DNS getaddrinfo ENOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!