How to change "default" docker-machine's dns settings
Asked Answered
H

2

29

I know how to create a new docker-machine with dns settings

docker-machine create -d virtualbox --engine-opt dns=8.8.8.8 my_machine

But there is already a "default" virtualmachine so is there a way to change its dns?

I read online ways to do this with boot2docker, but that tool is deprecated and docker-machine has replaced it. Unfortunately, it's so new that I haven't found much online about this.

Hodden answered 15/12, 2015 at 17:57 Comment(1)
My workaround is to remove the original "default" host and create a new one (same name) with the dns settings I needHodden
B
43

Go to ~/.docker/machine/machines/default/config.json and add your own DNS server into HostOptions/EngineOptions/Dns and restart docker machine.

{  
   "HostOptions": {
        "Driver": "",
        "Memory": 0,
        "Disk": 0,
        "EngineOptions": {
            "ArbitraryFlags": [],
            "Dns": ["192.168.99.1","8.8.8.8","8.8.4.4"], <-- set it here
            "GraphDir": ""
        }
}

Edit:

The Dns setting in config.json seems to be ignored in the new version of docker-machine. The only thing that seems to work is to add line (edit this to match your needs)

"${DOCKER_MACHINE}" ssh "${VM}" "sudo sed -i.bkp '/--label provider=virtualbox/a --dns 8.8.8.8\\\n--dns 8.8.4.4' /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart"

after

yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"

in script start.sh, which is run every time Docker Quickstart Terminal is started.

Then shut down the machine (if it's running) and open a new instance of the Docker Quickstart Terminal.

Bromberg answered 15/12, 2015 at 23:43 Comment(12)
I saw the config and thought this might be an option. But it wasn't referenced anywhere so I wasn't sure if this was the standard method encouraged by Docker...?Hodden
it might help others if you showed the contents of this config.json and a before/after snapshot of the settings for those who aren't familiar. I can accept this answer after that if a better one doesn't come upHodden
docker-machine is quite under documented. so config.json format is not publicly documented yetBromberg
In my config.json the "Dns" value was null. Replacing it with a list containing just the 8.8.x.x servers worked for me. I'm guessing the 192.168.99.1 is only needed if you have custom DNS entries set up locally.Soughtafter
In my config.json the "Dns" value is also null, however at the runtime the machine /etc/resolv.conf has 192.168.1.1 set for name server. I am trying to understand where this IP came from. Note that this IP does not work for me. More strange thing is that, the docker-machine and the containers used to able to reach out the outside world, i.e. the DNS used to work, but I don't know what the value was when it was working.Upturn
FYI -- You can also docker-machine provision name to apply any config changes without needing to restart the machine!Crafty
The DNS setting does not modify /etc/resolv.conf in the VM. That is tied up in VirtualBox networking. It modifies the DNS server that the Docker daemon itself uses.Crafty
Set this config to ["8.8.8.8", "8.8.4.4"], restarted docker machine, restarted docker service, then restarted docker machine, then reprovisioned it, then restarted it again for good measure. The machine is inexplicably trying to use 10.0.2.3 as DNS server.Mores
This didn't solve it for me. I put the DNS server 8.8.8.8 there and I'm still getting the same error.Danitadaniyal
This didn't solve it for me too. I put the DNS server in /etc/resolve.conf file inside the machine!!! dns addresses inside json.config don't apply on virtual machine(/etc/resolve.conf)Ault
anyone has solution to this? I recently ran into the same problem, and changing the Dns settings in config.json does not fix it.Priesthood
The only that seems to work is to add line "${DOCKER_MACHINE}" ssh "${VM}" "sudo sed -i.bkp '/--label provider=virtualbox/a --dns 8.8.8.8\\\n--dns 8.8.4.4' /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart" after yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}" in script start.sh that is run every time Docker Quickstart Terminal is started.Painterly
S
5

On Windows 10 docker's gui give some facilities.

Just right click on docker's icon in the tray bar and select "Settings" item.

Docker's options

Then, on the Docker's window, select the "Network" section and change the DNS option from "Automatic" to "Fixed" and hit "Apply". Docker will restart itself after that. I putted the Google's DNS (8.8.8.8) and it worked fine to me.

docker's network section with dns config

Hope it helps.

Stereography answered 2/11, 2017 at 23:21 Comment(1)
When I change this option to fixed and set an ip then check the resolv.conf in the container... it's unchanged. I don't believe this works.Uproar

© 2022 - 2024 — McMap. All rights reserved.