Bootstrap FreeKB - Docker - Assign DNS servers to a container using the docker run --dns command
Docker - Assign DNS servers to a container using the docker run --dns command

Updated:   |  Docker articles

By default, when a container is created and started using the docker run command, the container will have the DNS servers listed in the /etc/resolv.conf file on the Docker system. For example, let's say the docker system has the following.

~]# cat /etc/resolv.conf
nameserver 10.14.57.1
nameserver 10.14.57.2
search .

 

The docker exec command can be used to see that the container has inherited /etc/resolv.conf.

~]# docker exec container_name_or_id cat /etc/resolv.conf
nameserver 10.14.57.1
nameserver 10.14.57.2
search .

 

The --dns option can be used to override this behavior. 

docker run
--dns 192.168.0.2
--dns 192.168.0.3
hello-world

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c38375 in the box below so that we can be sure you are a human.