Setting DNS for Docker daemon on OS with systemd

前端 未结 2 1277
死守一世寂寞
死守一世寂寞 2020-12-28 08:23

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 &l         


        
2条回答
  •  借酒劲吻你
    2020-12-28 09:01

    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/.

提交回复
热议问题