Docker 101 : DNS - Domain Name Server - configuration for containers



Containers inherit their DNS information from the host they are running on.

Using a different DNS:

If we want our container to use a different DNS server we can mention it with the run command.
To check the DNS, we could get into the container and look at the "/etc/resolv.conf" file.


Once inside the container we check the "/etc/resolv.conf" file:


The "78491bf82846" string is the container ID.

Using the host's DNS server:

We can also run the container without any DNS information.
The "/etc/resolv.conf"  file in the container will look like our hosts "/etc/resolv.conf" file:


Inside the container the 
"/etc/resolv.conf" file shows the same DNS server as our host "10.124.23.98":


Configuring the DNS server for all containers:

We can also specify the DNS globally on the docker host by putting the DNS information in a "daemon.json" in the "/etc/docker" directory:


Then we would need to restart docker for the new configuration to take effect:


Comments

Leave as a comment:

Archive