背景:
使用自配置文件 /etc/docker/daemon.json
systemctl enable docker.service将docker加入服务
问题:
dockerd可以正常启动,但是systemctl start docker.service报错,如图:
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
使用journalctl -xe查看具体原因:
1月 24 08:19:15 vultr.guest 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.
1月 24 08:19:15 vultr.guest dockerd[3471]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the
1月 24 08:19:15 vultr.guest systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
1月 24 08:19:15 vultr.guest 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.
1月 24 08:19:15 vultr.guest systemd[1]: Unit docker.service entered failed state.
1月 24 08:19:15 vultr.guest systemd[1]: docker.service failed.
1月 24 08:19:17 vultr.guest systemd[1]: docker.service holdoff time over, scheduling restart.
1月 24 08:19:17 vultr.guest systemd[1]: Stopped Docker Application Container Engine.
-- Subject: Unit docker.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has finished shutting down.
1月 24 08:19:17 vultr.guest 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.
1月 24 08:19:17 vultr.guest dockerd[3475]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the
1月 24 08:19:17 vultr.guest systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
1月 24 08:19:17 vultr.guest 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.
实际上,上述最重要的是
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the
搜官网(https://docs.docker.com/config/daemon/),可以知道,是由于自配置的deamon.json和自动启动参数冲突。由于是systemctl启动,因此查看 /usr/lib/systemd/system/docker.service中的ExecStart项,发现其后面多了一句 -H unix:/,而我们的daemon.json指定了host。因此冲突。
将其删除即可。
systemctl daemon-reload
systemctl start docker.service
问题解决。