Docker启动失败报错Failed to start Docker Application Container Engine解决方案

在给一台腾讯云机器安装docker后发现无法启动,总是报错Failed to start Docker Application Container Engine,解决思路分享一下,以免各位童鞋踩坑。

1 安装Docker

说明:本文仅针对Linux CentOS 7环境下进行讲解,Mac版本请在官方下载Docker.dmg安装(留意:Macbook 没有yum、systemctl、service等Linux系统的命令,建议下载dmg桌面版Docker使用、配置方便。当然也可以brew install docker自己玩),Windows版本可以下载Docker exe安装包。

卸载已有 Docker

如果你已经安装过旧版的 Docker,可以先执行以下命令卸载旧版 Docker:
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine


安装 Docker

首次安装 Docker 之前,需要添加 Docker 安装源。添加之后,就可以从已经配置好的源去 安装和更新 Docker。添加 Docker 安装源的命令如下:
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

正常情况下,直接安装最新版本的 Docker 即可,因为最新版本的 Docker 有着更好的稳定性和安全性。也可以使用以下命令安装最新版本的 Docker: 
$ sudo yum install docker-ce docker-ce-cli containerd.io

注意:Linux CentOS 版本可以通过uname -r 来查看,必须在3.10版本之上才可以使用新版docker。比如我机器上的是3.10.0-1160.62.1.el7.x86_64。


如果想要安装指定版本的 Docker,可以使用以下命令查看到一批最近的docker历史版本列表:
$ sudo yum list docker-ce --showduplicates | sort -r

Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
Installed Packages
docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.14-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.14-3.el7                   @docker-ce-stable
docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.13-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.12-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.11-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.10-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.15-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.14-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.13-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 


然后选取想要的版本执行以下命令:

$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

安装完成后,使用以下命令启动 Docker。

$ sudo systemctl start docker

安装完成后,我们需要使用以下命令启动一个 hello world 的容器。

sudo docker run hello-world

如果看到输出了【Hello from Docker!】则说明docker可用。

其它命令比如docker ps -a查看所有镜像,自行学习即可。

2 Docker安装故障FAQ

2.1 安装Docker的版本选择

在Linux中对不同的安装方式产生的安装目录和文件均不相同,有的会默认放到/sbin或/opt或/usr/local下面,配置文件一般会在/etc下面。Docker也是一样,如果使用:

sudo yum install docker

来安装(建议均使用root权限),则安装的版本为1.13.1。

而如果按照上述第一节的做法,安装docker-ce版本,则最新是Docker version 20.10.14, build a224086。建议大家安装docker-ce版本。

2.2 启动失败

安装完毕后,通过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,发现如下错误行:

dockerd: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found

这句话的意思不就是iptables命令无法找到吗?那试图看下,cd /sbin目录查找iptables,竟然的确没有,用service iptables start也会报错:iptables: /sbin/iptables does not exist。

但是,/sbin目录下有个iptables_.sh文件!!是哪个应用修改了这个,不得而知,直接修改:

mv iptables_  iptables,再启动:service iptables start,成功了!

这时,再启动docker:systemctl start docker无输出但没报错了,通过systemctl status docker查看,状态是Active状态,表示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: active (running) since Sun 2022-04-10 19:32:05 CST; 41min ago
     Docs: https://docs.docker.com
 Main PID: 16216 (dockerd)
    Tasks: 14
   Memory: 38.3M
   CGroup: /system.slice/docker.service
           └─16216 /usr/bin/dockerd --containerd=/run/containerd/containerd.sock

Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.774479730+08:00" level=info msg="ccRes...=grpc
Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.774491097+08:00" level=info msg="Clien...=grpc
Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.800327122+08:00" level=info msg="[grap...lay2"
Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.805695934+08:00" level=info msg="Loadi...art."
Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.914702098+08:00" level=info msg="Defau...ress"
Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.027046047+08:00" level=info msg="Loadi...one."
Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.070391831+08:00" level=info msg="Docke...10.14
Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.070498814+08:00" level=info msg="Daemo...tion"
Apr 10 19:32:05 VM_17_5_centos systemd[1]: Started Docker Application Container Engine.
Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.107225048+08:00" level=info msg="API l...sock"
Hint: Some lines were ellipsized, use -l to show in full.

其它FAQ疑问欢迎大家持续留言给我来汇总归纳,谢谢~~

  • 34
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
你好,关于Docker报错 "Failed to start Docker Application Container Engine",可能有多种原因导致。以下是一些常见的解决方法,请尝试按照以下步骤进行排查和修复: 1. 检查Docker服务是否已启动:在终端或命令提示符中运行以下命令来启动Docker服务(如果尚未启动): - 在Linux上:`sudo service docker start` - 在Windows上:`net start docker` 2. 检查Docker的运行状态:运行以下命令查看Docker的状态: - 在Linux上:`sudo service docker status` - 在Windows上:`docker version` 3. 检查Docker的日志文件:Docker通常会生成日志文件,查看这些日志文件有助于了解错误的具体原因。日志文件的位置取决于您的操作系统: - 在Linux上:`/var/log/docker.log` - 在Windows上:`C:\ProgramData\Docker\logs\docker.log` 4. 检查系统资源:确保系统具有足够的资源(例如内存、磁盘空间)来运行Docker。如果资源不足,可以尝试释放一些资源或增加系统资源。 5. 检查端口冲突:确保Docker所使用的端口没有被其他应用程序占用。您可以尝试更改Docker的默认端口,或者通过终止占用端口的应用程序来解决冲突。 6. 重新安装Docker:如果以上方法都无法解决问题,您可以尝试重新安装Docker。确保您按照官方文档的指导进行操作,并且删除旧版本的Docker,然后重新安装最新版本。 如果您还有其他问题,请提供更多的细节,以便我能够更准确地帮助您解决问题。
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值