Docker Community Forums

Share and learn in the Docker community.

Cannot override hostname mapping in /etc/hosts in moby daemon


Recently I installed docker 1.13.1 on my new windows 10 machine, I needed to pull a image from a private repo which recently relocated and our dns server still had the old ip. With docker toolbox I used to be able to docker-machine ssh into the daemon and change the /etc/hosts file to hard-code a temporary ns mapping. Since there is no direct access provided to the new moby daemon I had to use this hack from the forum to get into it:
docker run -it --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh

I changed /etc/hosts in moby but when I do a pull it still uses the wrong ip from our internal dns, I had to change the docker dns to something like where the repo hostname doesn’t exit at all, only then the pull would resolve to the hard-coded ip in /etc/hosts.

So I guess there are 2 issues I want to raise here, first please provide default access to the daemon, I think there is really no point in hiding it, people who need it need it (for debugging issues etc.), and there are ways to hack into it anyway.

Secondly I think it’s a bug that dns lookup taking precedence over /etc/hosts (btw it would be nice if you can auto copy the windows hosts file into the daemon)

if you need to override dns, you could use --add-host.
That is like manipulating /etc/hosts

I’m not trying to run a container with custom dns, I want to change it for the docker daemon so it can resolve the ip of my private repo when I do a pull.

so you are saying that docker pull prefers the dns over your lokal /etc/hosts?

yes, I modified /etc/hosts in the docker daemon (moby), and when I pull it’s still using the dns