公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

目录
  • 前言
  • 1 安装Docker
    • 卸载已有 Docker
    • 安装 Docker
  • 2 Docker安装故障FAQ
    • 2.1 安装Docker的版本选择
    • 2.2 启动失败
  • 总结

    前言

    在给一台腾讯云机器安装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疑问欢迎大家持续留言给我来汇总归纳,谢谢~~

    总结

    分享到:
    标签:启动 失败 报错 服务器 解决办法
    用户无头像

    网友整理

    注册时间:

    网站:5 个   小程序:0 个  文章:12 篇

    • 51998

      网站

    • 12

      小程序

    • 1030137

      文章

    • 747

      会员

    赶快注册账号,推广您的网站吧!
    最新入驻小程序

    数独大挑战2018-06-03

    数独一种数学游戏,玩家需要根据9

    答题星2018-06-03

    您可以通过答题星轻松地创建试卷

    全阶人生考试2018-06-03

    各种考试题,题库,初中,高中,大学四六

    运动步数有氧达人2018-06-03

    记录运动步数,积累氧气值。还可偷

    每日养生app2018-06-03

    每日养生,天天健康

    体育训练成绩评定2018-06-03

    通用课目体育训练成绩评定