虚拟机上docker关机后开机就起不来了,具体异常如下

启动时:

[root@localhost docker]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

按照提示查看

[root@localhost docker]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2018-06-29 14:31:59 CST; 7s ago
     Docs: http://docs.docker.com
  Process: 2627 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=125)
 Main PID: 2627 (code=exited, status=125)

Jun 29 14:31:59 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
Jun 29 14:31:59 localhost.localdomain dockerd-current[2627]: flag provided but not defined: --init-path
Jun 29 14:31:59 localhost.localdomain dockerd-current[2627]: See '/usr/bin/dockerd-current --help'.
Jun 29 14:31:59 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=125/n/a
Jun 29 14:31:59 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Jun 29 14:31:59 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Jun 29 14:31:59 localhost.localdomain systemd[1]: docker.service failed.

执行journalctl -xe显示更详细的异常:

-- 
-- Unit docker.service has begun starting up.
Jun 29 13:49:23 localhost.localdomain dockerd-current[5059]: flag provided but not defined: --init-path
Jun 29 13:49:23 localhost.localdomain dockerd-current[5059]: See '/usr/bin/dockerd-current --help'.
Jun 29 13:49:23 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=125/n/a
Jun 29 13:49:23 localhost.localdomain 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.
Jun 29 13:49:23 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Jun 29 13:49:23 localhost.localdomain systemd[1]: docker.service failed.
Jun 29 13:49:23 localhost.localdomain polkitd[634]: Unregistered Authentication Agent for unix-process:5014:423047 (system bus name :1.40, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Jun 29 13:52:05 localhost.localdomain polkitd[634]: Registered Authentication Agent for unix-process:5079:439186 (system bus name :1.41 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Jun 29 13:52:05 localhost.localdomain systemd[1]: Starting Docker Storage Setup...
-- Subject: Unit docker-storage-setup.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
...........
...........

异常信息到这里,如果执行systemctl status docker.service时显示的错误码是125的请继续往下看,整个网上只在Stack Overflow上搜到一个相同错误的,而且他还没怎么解决。

弄了几个小时网上各种方案都不行,最终我把主要的信息点为以下两个:

1、Process: 2533 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=125)
2、flag provided but not defined: --init-path

这里给出的信息是没有定义init-path,二第一个信息列出来一系列的启动依赖,很显然是现在我本机的这些环境配置出了问题,所以我的出发点是从一台OK的节点上把相应的文件拷过来:

  • /usr/bin/dockerd-current
  • /usr/libexec/docker/docker-runc-current
  • /usr/libexec/docker/docker-proxy-current
  • /usr/libexec/docker/docker-init-current
  • /etc/docker/seccomp.json

    就这么多,拷贝到相应目录后docker正常启动了。

如果还是不行就把/etc/systemd/system/docker.service这个文件的内容也同步下。
期间可能要先执行systemctl daemon-reload然后再systemctl restart docker.service。

网上说的一些解决方案,如果一些文件找不到,如docker.sock等,可以执行sudo docker daemon -D

另外有一点要特别注意,很多方案说删掉/var/lib/docker/这个文件夹,但是我的建议是千万别这样做,要不然你的容器都会被干掉。是在不行可以先备份下来,弄好后再替换回来。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐