28

I want to set my resin/rpi-raspbian:jessie container's /etc/resolv.conf to:

nameserver 208.67.222.222
nameserver 208.67.220.220

My Dockerfile has the following line:

ADD resolv.conf /etc/resolv.conf

This added file contains the correct nameservers.

My Docker host's /etc/resolv.conf contains the correct information.

I'm running the container like this:

docker run -itd --cap-add=NET_ADMIN --device /dev/net/tun \
-v /home/pi/share/ovpn:/ovpn \
--privileged --network=internet_disabled --name vpn-client \
--dns=208.67.222.222 \
openvpn-client_nat-gateway /bin/bash

Despite all of this, the container gives this output:

root@642b0f4716ba:/# cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0

It's only after I change the resolv.conf manually from within the container (or with docker exec) that it looks right.

I'd rather avoid having to fix it with an exec command. Anybody have an idea what's going on here?

Kusalananda
  • 333,661

3 Answers3

21

AFAIK, docker overrides some files in an image when it's started, even if they were ADDed in Dockerfile. This for sure includes /etc/hosts, and most probably the same happens for /etc/resolv.conf too. This is apparently used to properly build the default "internal" network of Docker (so that images see each other, but not host, etc.) If you are really sure you want to override/modify some of those files, I believe you must do that as part of the runtime actions, that is as part of the CMD line. For example:

...
ADD resolv.conf /etc/resolv.conf.override
CMD cp /etc/resolv.conf.override /etc/resolv.conf && \
        your_old_commands...
akavel
  • 416
6

As I can see you are using user-defined networks and Docker Engine version >= 1.10. So from the official docker engine documentation about Embedded DNS server in user-defined networks:

These --dns IP addresses are managed by the embedded DNS server and will not be updated in the container's /etc/resolv.conf file.

Your dns has to work, but you will not see in any configuration file.

References.

GAD3R
  • 66,769
1

I have solved the issue if it is the web app for containers in Azure.

There are 2 containers mate. Kudu and the host

Steps

1.Install the ssh from your docker file ( also include a sshd config )

2.create a containerstart.sh ( which updates the resolv.conf)

3.Set the entry point inside there

Now the host resolv.conf gets updated and you can use any dns you desire

PS: If you can't pick up the custom DNS in the network do not worry. We could not either. Might need to resetup if you are using an ASE environment