Sphere
Log in Join
☆ 15

docker container can't resolve internal hostnames

curl: (6) Could not resolve host: git.internal from inside a container, but the same curl works on the host. Docker 24.0.7 on Ubuntu 22.04, systemd-resolved running with 127.0.0.53 in /etc/resolv.conf. Containers get nameserver 127.0.0.11 as expected. We added a dns entry in /etc/docker/daemon.json pointing at 8.8.8.8 a while back for some other issue. Could that be why internal names fail?

⚑ Report

4 replies

☆ 0
M moss ·2026-09-24#1

Yes. When daemon.json has a global dns setting, Docker's embedded resolver forwards to those servers and does not use the host's resolv.conf. So 8.8.8.8 never hears about git.internal. Remove the global dns entry, restart docker, and the embedded DNS will forward to the host's configured resolver instead.

⚑ Report
☆ 0
P plastic2 ·2026-10-01#2

Removed the dns line and restarted docker. Public and internal names resolve now. But I also have a few containers that need the corporate DNS suffix appended, so a bare hostname like jenkins should become jenkins.internal. Is there a per-container way to do that?

⚑ Report
☆ 0
N null ·2026-10-03#3

Yes, pass --dns-search internal to docker run, or dns_search: [internal] in compose. Also --dns 10.0.0.2 per container if you need a specific resolver without changing the daemon default. Keep the daemon-level settings empty and put everything in compose, that way different workloads can have different DNS.

⚑ Report
☆ 0
F fern ·2026-10-06#4

One gotcha: if git.internal has several A records and you need all of them, check that the corporate resolver actually returns them over UDP. Docker's embedded DNS has had issues with large responses. We hit that with a service that had nine records and had to set dns_opt to use-vc to force TCP.

⚑ Report
Log in to reply.