Docker启动失败问题解决:Job for docker.service failed because the control process exited with error code.....

寒山李白 2024-06-11 12:07:10 阅读 62

天行健,君子以自强不息;地势坤,君子以厚德载物。


每个人都有惰性,但不断学习是好好生活的根本,共勉!


文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。

文章目录

一、场景二、报错三、分析1. Docker状态查看2. 系统日志查看3. Dockerd查看 四、解决1. 键值检查2. 格式检查3. 删除或修改daemon.json文件4. 启动Docker5. 查看Docker 五、演示


一、场景

在搭建Harbor镜像仓库的时候配置insecure-registries参数,需要重启容器,然后重启失败了

二、报错

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.

三、分析

1. Docker状态查看

使用命令查看docker状态

systemctl status docker

输出主状态如下,好像也看不出是什么原因

● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2024-01-30 21:14:36 CST; 12h ago Docs: https://docs.docker.com Process: 4110 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE) Main PID: 4110 (code=exited, status=1/FAILURE)Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Service RestartSec=2s expired, scheduling restart.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.Jan 30 21:14:36 k8s-master systemd[1]: Stopped Docker Application Container Engine.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Start request repeated too quickly.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Failed with result 'exit-code'.Jan 30 21:14:36 k8s-master systemd[1]: Failed to start Docker Application Container Engine.

截图

在这里插入图片描述

2. 系统日志查看

然后还可以使用查看系统整体的最后两百行日志

tail -200f /var/log/messages

可能内容多且拥挤所以没找到原因

在这里插入图片描述

3. Dockerd查看

使用dockerd命令查看问题

dockerd

输出如下,这个命令好像能看出一些端倪,感谢某博主的这个dockerd命令,大家可根据输出内容百度查找适合自己的解决方法

unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: insecure-registies

前半段主要原因:unable to configure the Docker daemon with file /etc/docker/daemon.json:

大概意思就是说无法使用daemon.json文件配置docker的守护进程,就是这个json文件的问题

后半段具体原因:the following directives don't match any configuration option: insecure-registies

意思是因为重定向访问无法匹配配置参数insecure-registies,就是这个参数的问题

我的daemon.json文件内容如下:

在这里插入图片描述

到这里应该英文好的施主都能知道问题出在哪里了,我英语差且手残,英文单词registies是错误写法,正确的是registries

如果你跟我这个内容不一样,也是可以参考下面的解决方法

四、解决

1. 键值检查

本篇问题出现在键的单词写错了

正常daemon.json文件的内容是必须符合json格式要求的,且键值一一对应

键一般都是固定的写法,值则根据自己的情况填入

我将insecure-registies修改为正确的insecure-registries

重启docker即解决了这个报错

2. 格式检查

如果你的问题是json文件的问题,但后面写的不是参数问题,键值无误,可检查一下json格式是否正确

将内容复制后粘贴到在线json格式检查网站上检查一下

如果格式错了可修正后重启docker

3. 删除或修改daemon.json文件

如果上面以及网上其他方法都不能解决问题,终极的方法就是这个了,前提是该文件的配置没有了也不会影响你docker的使用

但像我这样在k8s集群中使用的话,里面配置了k8s相关的参数,没有这个文件会影响k8s,就无法使用这个方式解决

方法如下

直接删除daemon.json,命令如下,但不建议这样做

rm -f /etc/docker/daemon.json

为了后续还能改回来使用,可以修改格式使其失效

将daemon.json修改为daemon.text,等同于删除daemon.json

mv /ect/docker/daemon.json /etc/docker/daemon.text

4. 启动Docker

最后重新启动docker

systemctl restart docker

5. 查看Docker

systemctl status docker

在这里插入图片描述

五、演示

完整操作代码

[root@k8s-master ~]# systemctl status docker● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2024-01-30 21:14:36 CST; 12h ago Docs: https://docs.docker.com Process: 4110 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE) Main PID: 4110 (code=exited, status=1/FAILURE)Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Service RestartSec=2s expired, scheduling restart.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.Jan 30 21:14:36 k8s-master systemd[1]: Stopped Docker Application Container Engine.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Start request repeated too quickly.Jan 30 21:14:36 k8s-master systemd[1]: docker.service: Failed with result 'exit-code'.Jan 30 21:14:36 k8s-master systemd[1]: Failed to start Docker Application Container Engine.[root@k8s-master ~]# systemctl start dockerJob for docker.service failed because the control process exited with error code.See "systemctl status docker.service" and "journalctl -xe" for details.[root@k8s-master ~]# dockerdunable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: insecure-registies[root@k8s-master ~]# vim /etc/docker/daemon.json[root@k8s-master ~]# systemctl restart docker[root@k8s-master ~]# [root@k8s-master ~]# ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2024-01-31 11:26:43 CST; 14s ago Docs: https://docs.docker.com Main PID: 88041 (dockerd) Tasks: 65 Memory: 66.0M CGroup: /system.slice/docker.service ├─88041 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock └─88397 /usr/bin/docker-proxy -proto tcp -host-ip 127.0.0.1 -host-port 1514 -container-ip 172.18.0.8 -container-port 10514Jan 31 11:26:43 k8s-master dockerd[88041]: time="2024-01-31T11:26:43.379781201+08:00" level=warning msg="Not using native diff for overlay2, this may cause degraded performance for building images: kernel has CONFIG_OVERLAY_FS_REDIRECT_DIR enabled" storage-dr>Jan 31 11:26:43 k8s-master dockerd[88041]: time="2024-01-31T11:26:43.379956960+08:00" level=info msg="Docker daemon" commit=311b9ff graphdriver=overlay2 version=24.0.7Jan 31 11:26:43 k8s-master dockerd[88041]: time="2024-01-31T11:26:43.380043382+08:00" level=info msg="Daemon has completed initialization"Jan 31 11:26:43 k8s-master dockerd[88041]: time="2024-01-31T11:26:43.397548197+08:00" level=info msg="API listen on /run/docker.sock"Jan 31 11:26:43 k8s-master systemd[1]: Started Docker Application Container Engine.Jan 31 11:26:56 k8s-master dockerd[88041]: time="2024-01-31T11:26:56.574003576+08:00" level=info msg="ignoring event" container=7d0a423251a913898a85a68efb08ef6a8cd9b02ac614716f8b5041bb18b99125 module=libcontainerd namespace=moby topic=/tasks/delete type="*eve>Jan 31 11:26:57 k8s-master dockerd[88041]: time="2024-01-31T11:26:57.145364576+08:00" level=info msg="ignoring event" container=56936178be55a27b8daa16f0113c167c15a3a95f79ce4f58aef5b2aabb89b458 module=libcontainerd namespace=moby topic=/tasks/delete type="*eve>Jan 31 11:26:57 k8s-master dockerd[88041]: time="2024-01-31T11:26:57.282343246+08:00" level=info msg="ignoring event" container=6c8f765580a054d69eac07e2f79dbb33a49165580ae0e542a33d1e0e1e9d38ff module=libcontainerd namespace=moby topic=/tasks/delete type="*eve>Jan 31 11:26:57 k8s-master dockerd[88041]: time="2024-01-31T11:26:57.447774687+08:00" level=info msg="ignoring event" container=a42115d28e2f7998274f38b0b6235b489beb43adcbca516e6ba964c93d23dada module=libcontainerd namespace=moby topic=/tasks/delete type="*eve>Jan 31 11:26:57 k8s-master dockerd[88041]: time="2024-01-31T11:26:57.709667843+08:00" level=info msg="ignoring event" container=227806f882531c7b6619dd63a8c16fd29aaf3e3e229c6d10840966bc4b5175c1 module=libcontainerd namespace=moby topic=/tasks/delete type="*eve>


感谢阅读,祝君暴富!



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。