在 daemon.json 中配置主机后无法启动 docker
Unable to start docker after configuring hosts in daemon.json
我正在尝试使用配置文件 /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 状态 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 单元文件指定 -H fd://
,它与您的 tcp://0.0.0.0:1234
和 unix:///var/run/docker.sock
.
冲突
关于这个主题有很多 GitHub 个问题:
- https://github.com/moby/moby/issues/22339
- https://github.com/moby/moby/issues/21559
- https://github.com/moby/moby/issues/25471
- https://github.com/moby/moby/pull/27473
他们似乎不认为这是一个错误。但这绝对是一个烦恼。解决方法是复制默认单元文件并从中删除 -H fd://
:
$ sudo cp /lib/systemd/system/docker.service /etc/systemd/system/
$ sudo sed -i 's/\ -H\ fd:\/\///g' /etc/systemd/system/docker.service
$ sudo systemctl daemon-reload
$ sudo service docker restart
对于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 restart docker
。
我从网站上复制了 daemon.json。在 运行
之后
sudo systemctl stop docker
/usr/sbin/dockerd
它向我展示了一条更好的错误消息,指出我在 daemon.json 文件中有一个奇怪的不可见字符
在我的例子中,我尝试在 /etc/docker 下添加 daemon.json 和 /etc/systemd/system/docker.service.d 下的 *.conf 文件。
结果证明只有一个 .conf 文件就足够了(在我的例子中称为 override.conf):
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375
这样我就可以暴露 docker 套接字。
我在 Docker 文档上找到了它,它适用于 Docker 18.09.1 和 Centos 8:
要解决此问题,请创建一个包含以下内容的新文件 /etc/systemd/system/docker.service.d/docker.conf
,以删除默认启动守护程序时使用的 -H
参数。
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
然后重新加载
systemctl daemon-reload
原因是:
Docker 默认监听套接字。在使用 systemd
的 Debian 和 Ubuntu 系统上,这意味着启动 dockerd
时始终使用主机标志 -H
。如果您在 daemon.json
中指定 hosts
条目,这将导致配置冲突(如上述消息中所示)并且 Docker 无法启动。
我正在尝试使用配置文件 /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 状态 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 单元文件指定 -H fd://
,它与您的 tcp://0.0.0.0:1234
和 unix:///var/run/docker.sock
.
关于这个主题有很多 GitHub 个问题:
- https://github.com/moby/moby/issues/22339
- https://github.com/moby/moby/issues/21559
- https://github.com/moby/moby/issues/25471
- https://github.com/moby/moby/pull/27473
他们似乎不认为这是一个错误。但这绝对是一个烦恼。解决方法是复制默认单元文件并从中删除 -H fd://
:
$ sudo cp /lib/systemd/system/docker.service /etc/systemd/system/
$ sudo sed -i 's/\ -H\ fd:\/\///g' /etc/systemd/system/docker.service
$ sudo systemctl daemon-reload
$ sudo service docker restart
对于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 restart docker
。
我从网站上复制了 daemon.json。在 运行
之后sudo systemctl stop docker
/usr/sbin/dockerd
它向我展示了一条更好的错误消息,指出我在 daemon.json 文件中有一个奇怪的不可见字符
在我的例子中,我尝试在 /etc/docker 下添加 daemon.json 和 /etc/systemd/system/docker.service.d 下的 *.conf 文件。 结果证明只有一个 .conf 文件就足够了(在我的例子中称为 override.conf):
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375
这样我就可以暴露 docker 套接字。
我在 Docker 文档上找到了它,它适用于 Docker 18.09.1 和 Centos 8:
要解决此问题,请创建一个包含以下内容的新文件 /etc/systemd/system/docker.service.d/docker.conf
,以删除默认启动守护程序时使用的 -H
参数。
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
然后重新加载
systemctl daemon-reload
原因是:
Docker 默认监听套接字。在使用 systemd
的 Debian 和 Ubuntu 系统上,这意味着启动 dockerd
时始终使用主机标志 -H
。如果您在 daemon.json
中指定 hosts
条目,这将导致配置冲突(如上述消息中所示)并且 Docker 无法启动。