Docker DNS getaddrinfo ENOTFOUND

I run docker-compose with node:4.2.1-wheezy containers node:4.2.1-wheezy and dnsdock .

I have DOCKER_OPTS="--dns 172.17.42.1" inside / etc / default / docker.

When I run node -e "require('dns').resolve('host_name_here')" inside my node.js container, the host is correctly resolved through the 172.17.42.1 DNS server.

But when I run node -e "require('dns').lookup('host_name_here')" , it fails with an ENOTFOUND error.

And the problem is that http.request uses dns.lookup instead of dns.resolve .

The docs say dns.lookup calls getaddrinfo . And as far as I understand getaddrinfo caches / etc / resolv.conf and maybe it caches an empty /etc/resolv.conf nameserver 172.17.42.1 cat /etc/resolv.conf displays nameserver 172.17.42.1 ).

I really don't know how to solve this problem. What can cause this behavior?

Update 1.

 docker -v Docker version 1.7.1, build 786b29d docker-compose -v docker-compose version: 1.4.2 

Update 2.

I upgraded all versions to the latest versions (docker 1.9.0, docker-compose 1.5.0 and node to 5.0.0), but the problem still persists.

So this is the docker-compose.yml file that reproduces the problem:

 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 

You must replace 172.17.42.1 with the IP of your docker0 interface. setTimeout(..., 5000) required since the node container can start before dnsdock .

This is my docker-compose up output:

 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 
+6
source share
1 answer

For a better dns lookup, you might consider using network overlay, as presented in the Docker Overlay Networks section : it was easy

It uses the KV (Key / Value) storage base on Consul and a cluster of swarms where you can register your nodes.

You can create an overhead network

 eval "$(docker-machine env --swarm c0-master)" docker network create -d overlay myStack1 

And use it to launch the image:

 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 will be searchable by container name (regardless of the initial order). In addition, when the container restarts, it will remain open without cascading restarts.

+2
source

All Articles