When you are in a corporate environment, network is often configured to restrict outgoing requests, such as DNS resolution requests. By default, Docker uses Google DNS (8.8.8.8 and 8.8.4.4) to resolve domain names:
1 2 3 4 |
|
If you are in a corporate environment, resolution fails because you have to use your internal DNS server.
You can find many, many documentation about how to configure Docker DNS on Ubuntu (such as official Docker doc), but none of them answer these requirements all together:
1/ Configuration must be portable: works at home or at work or anywhere else
2/ Configuration must be written in files not provided by a deb package to avoid conflicts after package updates
Portable configuration
Ubuntu provides Dnsmasq, a local DNS server configured to use DNS server of your network through DHCP. Docker can’t use it because it doesn’t allow to use a local DNS server if its IP address is a local configuration, such as 127.0.0.1
.
So we’ll configure Dnsmasq to listen to another available IP address, such as the one provided by docker0
interface, to solve this issue.
Edit the new file /etc/NetworkManager/dnsmasq.d/docker.conf
(as sudo):
1
|
|
Then restart NetworkManager service:
1
|
|
Configure Docker DNS
Extract the IP address of the docker0
interface:
1 2 |
|
Then edit /etc/docker/daemon.json
(as sudo):
1 2 3 |
|
Restart Docker:
1
|
|
Finally, check DNS resolution works again:
1 2 3 4 5 6 |
|