Skip to content
Latchkey

Node.js "getaddrinfo EAI_AGAIN" inside a CI container

EAI_AGAIN is a temporary DNS failure: the resolver returned "try again" rather than a definitive "no such host." Inside a CI container this usually means the configured nameserver is unreachable or overloaded, /etc/resolv.conf is empty or wrong, or DNS is momentarily flaky. Because it is transient, a retry often succeeds, but a persistent EAI_AGAIN points at broken resolver config.

What this error means

A Node request fails with "Error: getaddrinfo EAI_AGAIN registry.npmjs.org" (or another host), often intermittently, inside a container-based job.

Terminal
Error: getaddrinfo EAI_AGAIN registry.npmjs.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:...)
  errno: -3001,
  code: 'EAI_AGAIN',
  hostname: 'registry.npmjs.org'

Common causes

The container resolver is unreachable or overloaded

The nameserver in /etc/resolv.conf cannot be reached from the container network, or it is dropping queries under load, so the lookup returns EAI_AGAIN.

Transient DNS flakiness

A momentary DNS hiccup returns "try again"; the same request succeeds on retry.

How to fix it

Check the resolver and retry

  1. Print /etc/resolv.conf and test resolution with getent hosts <host>.
  2. Point the container at a reachable DNS server if the current one fails.
  3. Add a short retry around the network call for genuinely transient failures.
Terminal
cat /etc/resolv.conf
getent hosts registry.npmjs.org || echo "DNS not answering"

Configure a reliable DNS server for the container

Set an explicit resolver the container can reach so lookups stop returning EAI_AGAIN.

docker-compose.yml
services:
  build:
    image: node:20
    dns:
      - 1.1.1.1
      - 8.8.8.8

How to prevent it

  • Configure reachable DNS servers for containers explicitly.
  • Add retries around DNS-dependent network calls in CI.
  • Verify /etc/resolv.conf is populated in custom images.

Frequently asked questions

What causes ""getaddrinfo EAI_AGAIN""?
The nameserver in /etc/resolv.conf cannot be reached from the container network, or it is dropping queries under load, so the lookup returns EAI_AGAIN.
How do I fix "getaddrinfo EAI_AGAIN"?
Check the resolver and retry

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card