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?
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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With