Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure which DNS server docker uses in Docker Desktop for Mac?

The built in DNS server in Docker Desktop for Mac is really slow, so I'd like to use a different DNS server by default. I know I can add --dns=... when running docker commands, but I'd like a way to set the default DNS server for all containers to avoid having to specify the DNS server individually for every container.

How can I set the default DNS server for all containers on Docker for Mac?

like image 222
Lars Nyström Avatar asked Jun 07 '17 10:06

Lars Nyström


2 Answers

In current versions of Docker for Mac, you can go to the Whale Icon -> Preferences -> Daemon -> Advanced and adjust the daemon level DNS settings with a daemon.json config. If your config is currently empty, this would add your own DNS setting with two entries:

{
  "dns": ["8.8.8.8", "192.168.0.1"]
}

If you already have content in here, then add an entry for "dns" to your json. See the daemon configuration documentation for other options you can add here.

like image 193
BMitch Avatar answered Sep 20 '22 22:09

BMitch


As a one liner:

sed -i '$s/}/,\n{"dns": ["8.8.8.8", "192.168.0.1"]}}/' ~/.docker/daemon.json

(For MacOS, the daemon configuration is in ~/.docker/daemon.json).

like image 45
RtmY Avatar answered Sep 20 '22 22:09

RtmY