Overriding Docker DNS servers

This little Docker peculiarity has tripped me up twice now; it got me again yesterday when I did a fresh install of ElementaryOS after they released Freya Beta 2.

There was a thing with Docker on Ubuntu where if your resolv.conf has as the nameserver (which it almost certainly does), then DNS lookups on containers would just fail. Docker fixed this with a workaround where all containers will have their nameservers overridden to point to Google DNS ( and

Except the corporate network I’m currently on uses OpenDNS, and has actually blocked the Google DNS IP addresses. Which meant that when my docker build process tried to kpm restore, it couldn’t find MyGet or NuGet or anything, resulting in a cascade of NameResolutionException errors.

I remembered having the problem before, and obviously I’d solved it, but I couldn’t remember how I solved it, so I figured it all out again from scratch, and now I’m posting it here for next time I reinstall Linux while working on a corporate network that blocks Google DNS:

Edit /etc/default/docker (you’ll need sudo for this) and uncomment the DOCKER_OPTS line, which lets you specify the command line arguments that are passed to the docker daemon when it starts. You can set the DNS servers using the --dns switch, like this:

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

Easy when you know how.

Share on facebook
Share on google
Share on twitter
Share on linkedin


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.