Konubinix' opinionated web of thoughts

How Docker Container DNS Works

Fleeting

docker, how should systemd-resolved and docker interact?,

Docker is coded in a smart way. When you run a new container on the docker host without any DNS related option in command, it simply copies host’s /etc/resolv.conf into container. While copying it filter’s out all localhost IP addresses from the file. That’s pretty obvious since that won’t be reachable from container network so no point in keeping them. During this filtering, if no nameserver left to add in container’s /etc/resolv.conf the file then Docker daemon smartly adds Google’s public nameservers 8.8.8.8 and 8.8.4.4 in to file and use it within the container.

https://kerneltalks.com/networking/how-docker-container-dns-works/

setup default dns servers in docker

How to use external DNS in all the containers on docker host You need to define the external DNS IP in docker daemon configuration file /etc/docker/daemon.json as below –

{ “dns”: [“10.2.12.2”, “3.4.5.6”] } Once changes saved in the file you need to restart docker daemon to pick up these new changes.

root@kerneltalks # systemctl docker restart and it’s done! Now any container you run fresh on your docker host will have these two DNS nameservers by default in it.

https://kerneltalks.com/networking/how-docker-container-dns-works/

docker /etc/resolv.conf is updated after reboot

Also, host and container /etc/resolv.conf always be in sync. Docker daemon takes help from the file change notifier and makes necessary changes in the container’s resolve file when there are changes made in the host’s file! The only catch is these changes will be done only if the container is not running. So to pick up changes you need to stop and start the container again. All stopped containers will be updated immediately after the host’s file changes

https://kerneltalks.com/networking/how-docker-container-dns-works/

Notes pointant ici