使用systemd在操作系统上设置Docker守护程序的DNS [英] Setting DNS for Docker daemon on OS with systemd
问题描述
Docker的默认DNS(例如8.8.8.8)在我工作时被阻止,因此我想更改默认值。我已经可以使用
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>
但是我想使用systemd插件来代替,因为官方的Docker文档推荐这个办法。我已经制作了一个 /etc/systemd/system/docker.service.d/dns.conf
文件,并使用了这样的东西:
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>
但我只是不知道变量名称应该是什么。如何设置?更重要的是,是否有一个页面记录了可以在Docker的systemd插件中使用的所有配置变量?
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,这是Ubuntu 15.10上的Docker 1.9,虽然我不怀疑任何错误)
(btw, this is Docker 1.9 on Ubuntu 15.10, although I don't suspect any bugs)
推荐答案
所有 .conf
/etc/systemd/system/docker.service.d
中的文件会从 /usr/lib/systemd/system/docker.service中重新设置
文件,这几乎是你尝试过的。
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.
而不是将 DNS = ..
行,您需要复制来自
文件到 /usr/lib/systemd/system/docker.service
文件中的ExecStart = dns.conf
(或 mydocker.conf
)。在守护程序
之后添加 - dns $ ip
部分 ExecStart
。例如:
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://
哪里 192.168.1.1
是dns服务器的ip。
Where the 192.168.1.1
is the ip of the dns server.
现在,通过systemctl和docker重新启动docker,现在应该用自己的dns重新启动。 (可以通过 systemctl status docker.service | grep dns
)。
Now restart docker via systemctl and docker should now restart with your own dns. (Checkable via systemctl status docker.service | grep dns
).
请注意,空 ExecStart =
是必需的,因为systemctl只会首先被清除为ExecStart。
Note that the empty ExecStart=
is required, as systemctl only will overrule the ExecStart if it is cleared first.
另请注意,一个 / etc / systemd / system /
中编辑文件后,需要使用systemctl守护程序重新加载。
Also note that a systemctl daemon-reload
is needed after editing files in /etc/systemd/system/
.
最后一点是,在某些系统上, docker.service
不在 / usr / lib / systemd / system /
,但在 / lib / systemd / system /
。
Last remark is that on some systems docker.service
is not located in /usr/lib/systemd/system/
, but in /lib/systemd/system/
.
这篇关于使用systemd在操作系统上设置Docker守护程序的DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!