Docker: Configure DNS for dockerd
Recently I realized, the network security makes it hard to run a local DNS server. When you are inside a container and realize, you are crippled due to the simple fact, there is no DNS. For some reason I was also unable to access the default Hyper-V DNS inside the container.
First I tried to manually replace the nameserver
in /etc/resolve.conf
. But that didn't help. Then I remembered I was connected to the more secure corp net. For that there was a simple fix:
- Pull the ethernet cable
- Disconnect from Corp WiFi
- Connect to the guest WiFi (yes guest config allows public DNS)
Finally I have DNS resolutions.
But that means I have to replace DNS config in /etc/resolve.conf
. Then I remembered that docker has --dns
argument. It didn't take much time to realize, docker build
doesn't have --dns
argument.
Search continues for more permanent solution.
Then today I was in daemon.json
for dockerd
. As a experiment, I added:
"dns": [
"1.1.1.1",
"8.8.8.8"
]
Finally, no need to add --dns
argument every time I ran a container at work, and docker build
works like charm.
Sometimes, it just pays off to just read the documentation.