Set custom DNS for Docker to use

DAR
2 min readJan 10, 2021

Did you know Docker internally uses Google DNS (8.8.8.8, 8.8.4.4) to resolve all domains when downloading images or installing dependencies while building images ?

Recently while building Smart Display with Phoenix LiveView I found that’s the case when suddenly all new image downloads or build dependencies that were not cached started failing. As I run my own Ad blocking VPN with DoH and have a sink setup on my router for Google DNS as many of the devices for e.g Chromecast come hard coded with Google DNS to allow serving ads and geo lock your content.

Initially I couldn’t figure out what could be the cause as this was something unexpected that docker by default is using Google DNS if nothing is configured.

First I had to update in /etc/default/docker for docker to be able to download dependencies

# Use DOCKER_OPTS to modify the daemon startup options. DOCKER_OPTS="--dns 1.1.1.1 --dns 1.0.0.1"

but I hit a wall when the images that were not available locally started to fail as well up on further digging through found online that DNS config should also be updated in /etc/docker/daemon.json

{ "dns": ["1.1.1.1", "1.0.0.1"] }

For now this has resolved my Docker DNS issues and all images and dependencies are working well.

Originally published at https://dev.to on January 10, 2021.

--

--

DAR

Coder during the day, squash player in the evening and cricketer over the weekends. Doubts are the ants in the pants, that keep faith moving