The default DNS for Docker (e.g. 8.8.8.8) is blocked where I work, so I want to change the default. I've been able to do this using
$ docker daemon --dns <mydnsaddress>
but I want to do this using a systemd drop-in instead, since the official Docker docs recommend this way. I've made a /etc/systemd/system/docker.service.d/dns.conf
file, and used things like this:
[Service]
DNS=<mydnsaddress>
But I just have no idea what the variable name is supposed to be. How do I set this? More importantly, is there a page that documents all config variables that can be used in systemd drop-ins for Docker?
(btw, this is Docker 1.9 on Ubuntu 15.10, although I don't suspect any bugs)
--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 .
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.
The location of systemd configuration files are different when running Docker in rootless mode. When running in rootless mode, Docker is started as a user-mode systemd service, and uses files stored in each users' home directory in ~/.config/systemd/user/docker.service.d/ .
All .conf
files in /etc/systemd/system/docker.service.d
overrule the settings from the /usr/lib/systemd/system/docker.service
file, which is almost what you tried.
Instead of putting a DNS=..
line in, you need to copy the ExecStart=
part from the /usr/lib/systemd/system/docker.service
file to dns.conf
(or mydocker.conf
). Add --dns $ip
after the daemon
part of the ExecStart
. E.g.:
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon --dns 192.168.1.1 -H fd://
Where the 192.168.1.1
is the ip of the dns server.
Now restart docker via systemctl and docker should now restart with your own dns. (Checkable via systemctl status docker.service | grep dns
).
Note that the empty ExecStart=
is required, as systemctl only will overrule the ExecStart if it is cleared first.
Also note that a systemctl daemon-reload
is needed after editing files in /etc/systemd/system/
.
Last remark is that on some systems docker.service
is not located in /usr/lib/systemd/system/
, but in /lib/systemd/system/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With