本文来自 codeday ,作者 codeday
我正在尝试使用配置文件/etc/docker/daemon.json在ubuntu 16.04中配置docker(版本17.03.1-ce)来添加主机:
{
"debug": true,
"hosts": ["tcp://0.0.0.0:1234", "unix:///var/run/docker.sock"],
"dns" : ["8.8.8.8","8.8.4.4"]
}
复制代码
当我尝试重新启动docker时…它失败了
#service docker restart
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
复制代码
在systemctl status上观看docker.service:
Starting Docker Application Container Engine...
docker-slave-ubuntu-build dockerd[24806]: unable to configure the Docker daemon with file /etc/docker/daemon.json:
the following directives are specified both as a flag and in the configuration file:
hosts: (from flag: [fd://], from file: [tcp://0.0.0.0:4243 unix:///var/run/docker.sock])
复制代码
我可以在哪里删除提到的旗帜?我必须修改维护者的脚本?
最佳答案
对于systemd,我首选的方法是部署一个简单的覆盖文件(您可能需要先创建目录):
$cat /etc/systemd/system/docker.service.d/override.conf
# Disable flags to dockerd, all settings are done in /etc/docker/daemon.json
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
复制代码
这将从dockerd中删除-H …默认标志以及任何其他选项,并允许您从daemon.json文件管理docker.这也允许docker更改其启动脚本,只要它们不修改ExecStart并且您将继续接收这些更改而不维护您自己的docker.service副本.
创建此文件后,运行systemctl daemon-reload; systemctl重启docker.