Docker - Assign DNS servers to a container using the docker run --dns command
by
Jeremy Canfield |
Updated: February 13 2022
| 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