DEV Community

Ahsan Nabi Dar
Ahsan Nabi Dar

Posted on

Set custom DNS for Docker to use

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"
Enter fullscreen mode Exit fullscreen mode

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"]
}

Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)