How to change the dns of a running docker container
the default dns 22.214.171.124 and 126.96.36.199 are blocked by my nation’s firewall, and I do not want to stop the container for I install a lot of software in it.
One Solution collect form web for “How to change the dns of a running docker container”
If you want to change the DNS, you can just do it in the same way you would on a normal host and this should just work. For example editing the
/etc/resolv.conf file in the container.
Although if it is entirely blocked, I’d recommend a more permanent solution.
/etc/default/docker (may be
/etc/default/docker.io on Debian based hosts) you can add a line to set the default DNS on new containers. This line would look something like
DOCKER_OPTS="-dns 188.8.131.52 -dns 184.108.40.206"
You can just add a new
-dns x.x.x.x for every DNS server you wish to use to resolve.
Once you have done this you will need to restart the Docker process. This is done in a few ways depending on the host again. For Debian based hosts:
service docker.io restart
docker run a new container, it will have those DNS servers set.