DEV Community

Ahsan Nabi Dar
Ahsan Nabi Dar

Posted on

5

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay