git/curl "Could not resolve host" (DNS in containers) in CI
The client asked the resolver to look up a hostname and got nothing back. This is name resolution failing outright: the DNS server is unreachable, unset, or has no record, so no connection is even attempted.
What this error means
git, curl, npm, or apt stops with "Could not resolve host: <name>". curl reports exit code 6. It commonly appears only inside a job container, while the host runner resolves the same name.
curl: (6) Could not resolve host: github.com
fatal: unable to access 'https://github.com/org/repo.git/':
Could not resolve host: github.comCommon causes
The container has no working resolver
A job container with an empty or wrong /etc/resolv.conf (no nameserver line, or one pointing at an unreachable server) cannot resolve any name.
The name genuinely does not exist
A typo in the host, or an internal name that only resolves on a private DNS the runner cannot reach, returns NXDOMAIN.
How to fix it
Give the container a reachable nameserver
- Print
/etc/resolv.confinside the failing step to see if anameserveris set. - Configure a resolver for the container (for example via the service/container
dnsoption or a Docker daemondnssetting). - Re-run and confirm
getent hosts <name>now returns an address.
container:
image: node:20
options: --dns 8.8.8.8Confirm the name resolves at all
Test resolution directly so you know whether the resolver or the record is the problem.
getent hosts github.com || nslookup github.comHow to prevent it
- Pin a known-good
--dnsfor job containers instead of inheriting an empty resolv.conf. - Use fully qualified hostnames so a bad search domain cannot mangle the lookup.
- Verify internal names resolve from the runner network before relying on them in CI.