Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 630
kane Avatar asked Dec 15 '15 17:12

kane


People also ask

What is the command to set DNS server for all Docker containers?

--dns=IP_ADDRESS Add the DNS server to the /etc/resolv. conf of the container and let the container use this server to resolve all hostnames that are not in /etc/hosts . --dns-search=DOMAIN sets the search domain of the container. When the search domain is set to .

How do I find my Docker DNS?

Run docker network ls to get the running networks names, and then docker network inspect NETWORK_NAME to see the containers in it. Look for the "Containers" keyword in the JSON, it is a list of connected devices. Look for the instance with the "IPv4Address": "127.0. 0.11/24" entry, the "Name" key is the DNS name.

Do Docker containers use host DNS?

DNS services conf configuration file. Containers that use the default bridge network get a copy of this file, whereas containers that use a custom network use Docker's embedded DNS server, which forwards external DNS lookups to the DNS servers configured on the host.


1 Answers

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.

like image 177
Nat Avatar answered Sep 28 '22 10:09

Nat