欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker报错Job for docker.service failed because the control process exited with error code.

程序员文章站 2022-04-28 11:59:16
...

配置加速镜像之后启动docker一直报错
Job for docker.service failed because the control process exited with error code. See “systemctl status docker.service” and “journalctl -xe” for details.
Docker报错Job for docker.service failed because the control process exited with error code.查看docker状态之后显示如下信息

83906 ExecStart=/usr/bin/dockerd $DOCKER_OPTS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $DOCKER_DNS_OPTIONS $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
错误原因:
docker的socket配置出现了冲突,docker在运行时的启动入口文件为:/lib/systemd/system/docker.service,我们在配置镜像加速之后又添加了一个守护进程文件:/etc/docker/daemon.json,两个文件对host进行了配置,发生冲突。
解决办法
①首先查看/etc/docker/daemon.json文件的配置信息是否正确

{
 "registry-mirrors":["http://hub-mirror.c.163.com"]
}

修改完成保存退出即可,重新加载daemon.json

systemctl daemon-reload

启动:docker查看

systemctl start docker

Docker报错Job for docker.service failed because the control process exited with error code.
②将加速器地址添加到配置文件的启动命令即可
备份docker.service文件

 cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service

将镜像加速器地址添加到docker的启动命令

sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror=自己的镜像地址|g" /etc/systemd/system/docker.service

本文中配置的是网易的镜像加速,修改命令为,复制执行即可

sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror={http://hub-mirror.c.163.com|g" /etc/systemd/system/docker.servic

然后重新加载daemon.json,再启动docker即可

systemctl daemon-reload
systemctl start docker

Docker报错Job for docker.service failed because the control process exited with error code.
③(尝试了这个方式,没有成功,方法②确定正确)将docker启动入口文件中的-H fd://删除再重启服务,或者在启动入口配置监听的端口和本地socket信息:

vim /lib/systemd/system/docker.service

Docker报错Job for docker.service failed because the control process exited with error code.Docker报错Job for docker.service failed because the control process exited with error code.

将ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS改为

ExecStart=/usr/bin/dockerd

或改为

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

最后启动或者重启docker即可Docker报错Job for docker.service failed because the control process exited with error code.