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.

1
  • My workaround is to remove the original "default" host and create a new one (same name) with the dns settings I need
    – kane
    Dec 15, 2015 at 21:13

2 Answers 2

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.

12
  • 1
    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.
    – amacleod
    Jun 9, 2016 at 15:47
  • 3
    FYI -- You can also docker-machine provision name to apply any config changes without needing to restart the machine! Jan 27, 2017 at 19:32
  • 1
    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. Jan 27, 2017 at 19:35
  • 2
    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. Sep 25, 2017 at 21:38
  • 1
    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. Aug 21, 2018 at 9:25
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.

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. Jul 16, 2018 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.