moby: DNS queries inside docker fail with Error: getaddrinfo EAI_AGAIN

We are using Bamboo to build a complete docker container with a NodeJS application. During building the docker is started and npm is used to download all the depending frameworks. The build fails because it seems like some of the DNS queries fail with getaddrinfo EAI_AGAIN registry.npmjs.org:443

Has anyone experienced the same problem?

...
25-mar-2017 09:06:14	npm info using npm@3.10.10
25-mar-2017 09:06:14	npm info using node@v6.9.5
...
25-mar-2017 09:07:24	npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
...
25-mar-2017 09:08:24	npm http request GET https://registry.npmjs.org/supertest
25-mar-2017 09:08:29	npm ERR! Linux 4.4.0-66-generic
25-mar-2017 09:08:29	npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
25-mar-2017 09:08:29	npm ERR! node v6.9.5
25-mar-2017 09:08:29	npm ERR! npm  v3.10.10
25-mar-2017 09:08:29	npm ERR! code EAI_AGAIN
25-mar-2017 09:08:29	npm ERR! errno EAI_AGAIN
25-mar-2017 09:08:29	npm ERR! syscall getaddrinfo
25-mar-2017 09:08:29	
25-mar-2017 09:08:29	npm ERR! getaddrinfo EAI_AGAIN registry.npmjs.org:443
25-mar-2017 09:08:29	npm ERR! 
25-mar-2017 09:08:29	npm ERR! If you need help, you may report this error at:
25-mar-2017 09:08:29	npm ERR!     <https://github.com/npm/npm/issues>
25-mar-2017 09:08:29	
25-mar-2017 09:08:29	npm ERR! Please include the following file with any support request:
25-mar-2017 09:08:29	npm ERR!     /app/npm-debug.log
25-mar-2017 09:08:29	The command '/bin/sh -c npm install' returned a non-zero code: 1
25-mar-2017 09:08:29	
...

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

This known issue is discussed in detail here: https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/

Simple fix is to create the file /etc/docker/daemon.json

and insert:

{
    "dns": ["10.0.0.2", "8.8.8.8"]
}

where 10.0.0.2 is the first DNS server your machine requests records from, and 8.8.8.8 is the fallback DNS server, google in this case.

If you are using VPN and docker has problems with DNS try:

  1. Connect to VPN
  2. cat /etc/resolv.conf
  3. Copy generated DNSes
  4. Insert copied DNSes into /etc/docker/daemon.json as follows:
{
    "dns": ["a1.a2.a3.a4", "b1.b2.b3.b4"]
}
  1. sudo service docker restart

This worked for me.

For me it helped to run “docker-compose up -d” again. The problem was the old docker instance was created in a different session with a different wifi network etc.

For anyone reading this … there might be multiple root causes to DNS issues. If they happen always: likely you’re facing external network restrictions like described in the above mentioned https://robinwinslow.uk/fix-docker-networking-dns IF the issues happens rarely (up to 10% of attempts) it’s likely due to Alpine restrictions, described https://github.com/gliderlabs/docker-alpine/blob/master/docs/caveats.md#dns

Solutions do vary from not using alpine-based docker images … to creating a local DNS cache manually as a side car, or other workarounds as well. It helps reading the above links to understand the root cause of your DNS issue 😉

In my case removing "iptables": false from /etc/docker/daemon.json fixed the problem. I was using this because docker iptables were messing ports closed by ufw and made by nginx. So I don’t know what to do now… seems like whenever I want to install a new dep I have to enable and disable it back again.

@danger89 The remark from Melroy van den Berg on this Stack Overflow thread can help you : https://stackoverflow.com/a/61955468 EDIT: Sorry I didn’t know it was actually you.

@danger89 The remark from Melroy van den Berg on this Stack Overflow thread can help you : https://stackoverflow.com/a/61955468 EDIT: Sorry I didn’t know it was actually you.

Who is Melroy? Hahah. Yea it’s me. 🤣

For me it helped to run “docker-compose up -d” again. The problem was the old docker instance was created in a different session with a different wifi network etc.

So I have multiple Docker images using NodeJS (based on node:lts-alpine). All those docker containers has this “getaddrinfo issue”, but only right after a system reboot. Restarting those specific docker containers indeed solve the issue temporally. But the (VERY HIGH) likelihood it fails again after a system reboot is still present until today.

I would like to solve this problem once and for all. My guess is there is a network dependency issue in Docker or within NodeJS docker image. Either way maybe the app in the docker container is trying to access the internet before the network is up? Or!? Help me… This issue is causing 3 years of brain pain for me.

This known issue is discussed in detail here: https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/

Simple fix is to create the file /etc/docker/daemon.json

and insert:

{
    "dns": ["10.0.0.2", "8.8.8.8"]
}

where 10.0.0.2 is the first DNS server your machine requests records from, and 8.8.8.8 is the fallback DNS server, google in this case.

Didn’t work for me. The DNS in /etc/resolv.conf comes from DHCP and is managed by the cloud service provider. It doesn’t/wouldn’t contain the DNS records of docker containers.

When I did docker container inspect mycontainer, it was shown as connected to the docker network I had created but when I did docker network inspect mynetwork, the container was not shown as being connected to the network.

I tried docker network connect mynetwork mycontainer. It didn’t help.

Restarting the container solved the problem.

If you are using VPN and docker has problems with DNS try:

  1. Connect to VPN
  2. cat /etc/resolv.conf
  3. Copy generated DNSes
  4. Insert copied DNSes into /etc/docker/daemon.json as follows:
{
    "dns": ["a1.a2.a3.a4", "b1.b2.b3.b4"]
}
  1. sudo service docker restart

This worked for me.

This, this is what I came here for. Thank you kind sir.

Ignore this problem. The build server had net.ipv4.ip_forward = 0 in /etc/sysctl.conf so the build could not reach the internet.