微信扫一扫 分享朋友圈

已有 1222 人浏览分享

开启左侧

解决Docker启动报错Failed to start Docker Application Container Engine

[复制链接]
1222 0
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

  1. Repository epel is listed more than once in the configuration
  2. Loading mirror speeds from cached hostfile
  3. Loaded plugins: fastestmirror, langpacks
  4. Installed Packages
  5. docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable
  6. docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable
  7. docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable
  8. docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable
  9. docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable
  10. docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable
  11. docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable
  12. docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable
  13. docker-ce.x86_64            3:20.10.14-3.el7                   docker-ce-stable
  14. docker-ce.x86_64            3:20.10.14-3.el7                   @docker-ce-stable
  15. docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable
  16. docker-ce.x86_64            3:20.10.13-3.el7                   docker-ce-stable
  17. docker-ce.x86_64            3:20.10.12-3.el7                   docker-ce-stable
  18. docker-ce.x86_64            3:20.10.11-3.el7                   docker-ce-stable
  19. docker-ce.x86_64            3:20.10.10-3.el7                   docker-ce-stable
  20. docker-ce.x86_64            3:20.10.0-3.el7                    docker-ce-stable
  21. docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable
  22. docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable
  23. docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable
  24. docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable
  25. docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable
  26. docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable
  27. docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable
  28. docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable
  29. docker-ce.x86_64            3:19.03.15-3.el7                   docker-ce-stable
  30. docker-ce.x86_64            3:19.03.14-3.el7                   docker-ce-stable
  31. docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable
  32. docker-ce.x86_64            3:19.03.13-3.el7                   docker-ce-stable
  33. docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable
  34. docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable
  35. docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable
  36. docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable
  37. docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable
  38. docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable
  39. docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable
  40. docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable
  41. docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable
  42. docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable
  43. docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable
  44. docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable
  45. docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable
  46. docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable
  47. docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable
  48. docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable
  49. docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable
  50. docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable
  51. docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable
  52. docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable
  53. docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable
  54. docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable
  55. docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable
  56. docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable
  57. docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable
  58. docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable
  59. docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable
  60. docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable
  61. docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable
  62. docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
  63. 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:

  1. [root@VM_17_5_centos init.d]# systemctl status docker
  2. ● docker.service - Docker Application Container Engine
  3.    Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  4.    Active: failed (Result: start-limit) since Sun 2022-04-10 19:09:56 CST; 11s ago
  5.      Docs: https://docs.docker.com
  6.   Process: 14592 ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
  7. Main PID: 14592 (code=exited, status=1/FAILURE)

  8. Apr 10 19:09:54 VM_17_5_centos systemd[1]: docker.service failed.
  9. Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service holdoff time over, scheduling restart.
  10. Apr 10 19:09:56 VM_17_5_centos systemd[1]: Stopped Docker Application Container Engine.
  11. Apr 10 19:09:56 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service
  12. Apr 10 19:09:56 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine.
  13. Apr 10 19:09:56 VM_17_5_centos systemd[1]: Unit docker.service entered failed state.
  14. Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service failed.
  15. Apr 10 19:10:00 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service
  16. Apr 10 19:10:00 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine.
  17. 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运行正常了!

  1. [root@VM_17_5_centos init.d]# systemctl status docker
  2. ● docker.service - Docker Application Container Engine
  3.    Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  4.    Active: active (running) since Sun 2022-04-10 19:32:05 CST; 41min ago
  5.      Docs: https://docs.docker.com
  6. Main PID: 16216 (dockerd)
  7.     Tasks: 14
  8.    Memory: 38.3M
  9.    CGroup: /system.slice/docker.service
  10.            └─16216 /usr/bin/dockerd --containerd=/run/containerd/containerd.sock

  11. 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
  12. 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
  13. 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"
  14. 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."
  15. 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"
  16. 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."
  17. 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
  18. 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"
  19. Apr 10 19:32:05 VM_17_5_centos systemd[1]: Started Docker Application Container Engine.
  20. 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"
  21. Hint: Some lines were ellipsized, use -l to show in full.
复制代码
免责声明:
1,海欣资源网所发布的资源由网友上传和分享,不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
2,海欣资源网的资源来源于网友分享,仅限用于学习交流和测试研究目的,不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。
3,海欣资源网所发布的资源由网友上传和分享,版权争议与本站无关,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。
4,如果您喜欢,请支持正版,购买正版,得到更好的正版服务,如有侵权,请联系我们删除并予以真诚的道歉,联系方式邮箱 haixinst@qq.com
海欣资源-企业信息化分享平台。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

0

关注

0

粉丝

19

主题
热度排行
回复排行
最新贴子

Archiver|手机版|海欣资源 ( 湘ICP备2021008090号-1 )|网站地图

GMT+8, 2024-3-29 07:07 , Gzip On, MemCached On.

免责声明:本站所发布的资源和文章均来自网络,仅限用于学习交流和测试研究目的,不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站信息来自网络,版权争议与本站无关,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 如果您喜欢,请支持正版,购买正版,得到更好的正版服务,如有侵权,请联系我们删除并予以真诚的道歉。