由于需要修改docker api 安全漏洞,关闭对外的2375端口。修改 /usr/lib/systemd/system/docker.service
文件启动参数,统一到 /etc/docker/daemon.json
配置
原 docker.service
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
新 docker.service
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
原 daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"data-root":"/home/docker/datadir"
}
新 daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"data-root":"/home/docker/datadir",
"hosts": ["tcp://127.0.0.1:2375","unix:///var/run/docker.sock"]
}
执行重启docker
[root]$ systemctl daemon-reload && systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
查看日志,提示关键错误 the following directives are specified both as a flag and in the configuration file: hosts
[root]$ journalctl -xe
7月 29 08:24:37 node1 systemd[1]: Starting Docker Application Container Engine...
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has begun starting up.
7月 29 08:24:37 node1 dockerd[32143]: 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 fir/daemon.json: the following directives are specified both as a flag and in the configuration file: hosts: (from flag: [fd://], from file: [tcp://127.0.0.1:2375 unix:///var/run/docker.sock])
7月 29 08:24:37 node1 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
7月 29 08:24:37 node1 systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has failed.
--
-- The result is failed.
7月 29 08:24:37 node1 systemd[1]: Unit docker.service entered failed state.
7月 29 08:24:37 node1 systemd[1]: docker.service failed.
仔细检查配置 docker.service
发现前面还有一个 -H fd://
迁移配置时删漏了,去掉后服务启动成功
可用 docker.service
[Service]
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock