一、发现问题
在一个很久没用docker的虚拟机上想跑一个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.
从这个错误看不出来什么信息,就运行systemctl status docker
去看下运行状态。
然而没发现什么特别
[root@VM_17_5_centos init.d]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Sun 2022-04-10 19:09:56 CST; 11s ago
Docs: https://docs.docker.com
Process: 14592 ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 14592 (code=exited, status=1/FAILURE)
Apr 10 19:09:54 VM_17_5_centos systemd[1]: docker.service failed.
Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service holdoff time over, scheduling restart.
Apr 10 19:09:56 VM_17_5_centos systemd[1]: Stopped Docker Application Container Engine.
Apr 10 19:09:56 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service
Apr 10 19:09:56 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine.
Apr 10 19:09:56 VM_17_5_centos systemd[1]: Unit docker.service entered failed state.
Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service failed.
Apr 10 19:10:00 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service
Apr 10 19:10:00 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine.
Apr 10 19:10:00 VM_17_5_centos systemd[1]: docker.service failed.
唯一的一句错误是Failed to start Docker Application Container Engine.
网上其它文章的如下几个解决方案均无法生效:
1)修改 /etc/docker/daemon.json
添加registry-mirrors镜像地址:这个是用于加速的,跟启动失败一般不会有关系。
2)删除/etc/docker/daemon.json
:根本没必要删除,用docker官网的镜像太慢了,肯定要配置国内的镜像源的。跟启动失败也不会有关系。
3)修改Docker Container Engine
的配置文件:
有的文章建议去修改/usr/lib/systemd/system/docker.service
配置文件,个人觉得是根本没有必要。虽说从错误信息看是有
Process: 14592 ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 14592 (code=exited, status=1/FAILURE)
这样一句,但本质上原生安装包不可能刚安装就有问题还需要用户自己修改什么。
二、解决问题
鉴于上述几点都无法解决,就想到查看Linux系统操作日志(最后200行就可以排查):
tail -200f /var/log/messages
此时,再次输入systemctl start docker试图启动docker,发现如下错误行:
May 12 12:08:56 centos7 systemd: Starting Docker Application Container Engine...
May 12 12:08:56 centos7 dockerd: time="2023-05-12T12:08:56.795427099+08:00" level=info msg="Starting up"
May 12 12:08:56 centos7 dockerd: failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
May 12 12:08:56 centos7 systemd: docker.service: main process exited, code=exited, status=1/FAILURE
May 12 12:08:56 centos7 systemd: Failed to start Docker Application Container Engine.
May 12 12:08:56 centos7 systemd: Unit docker.service entered failed state.
May 12 12:08:56 centos7 systemd: docker.service failed.
其中的May 12 12:08:56 centos7 dockerd: failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
这句报错可以发现docker的守护程序没找到pid文件。按提示使用ps -aux | grep docker
命令查看还有没有没退出的docker进程,如果有的话就使用kill
关闭。这次我是启动不成功,就没关于docker的进程。
然后按提示删除文件,使用命令:rm -r /var/run/docker.pid
然后确定删除。
最后再使用systemctl start docker
启动,发现已经成功启动docker了。