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.
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
- Print
/etc/resolv.confand test resolution withgetent hosts <host>. - Point the container at a reachable DNS server if the current one fails.
- Add a short retry around the network call for genuinely transient failures.
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.
services:
build:
image: node:20
dns:
- 1.1.1.1
- 8.8.8.8How to prevent it
- Configure reachable DNS servers for containers explicitly.
- Add retries around DNS-dependent network calls in CI.
- Verify
/etc/resolv.confis populated in custom images.