docker报错Container is not running问题及解决

 更新时间:2023年05月18日 15:03:27   作者:曹天骄  
这篇文章主要介绍了docker报错Container is not running问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

docker报错Container is not running

我在运行docker exec -it 56b90db5253e /bin/bash报错。

出现这个问题,是因为Container容器之前已经启动过了

需要执行docker start 56b90db5253e就可以解决了。

docker启动失败报错Failed to start Docker Application Container Engine

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

安装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查看所有镜像,自行学习即可。

Docker安装故障FAQ

安装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版本。

启动失败

安装完毕后,通过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.

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Docker容器添加映射端口的两种实现方法

    Docker容器添加映射端口的两种实现方法

    本文主要介绍了Docker容器添加映射端口的两种实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-07-07
  • 详解CentOS 7 : Docker私有仓库搭建和使用

    详解CentOS 7 : Docker私有仓库搭建和使用

    本篇文章主要介绍了详解CentOS 7 : Docker私有仓库搭建和使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • 基于docker Desktop一键式搭建k8s环境的步骤

    基于docker Desktop一键式搭建k8s环境的步骤

    在docker desktop中一键启动k8s环境很简单,下面介绍如何启动dashboard,dashboard仪表盘是新手学习k8s至关重要的一个工具,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧
    2023-11-11
  • docker中修改镜像容器的存放目录的方法

    docker中修改镜像容器的存放目录的方法

    本篇文章主要介绍了docker中修改镜像容器的存放目录的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-07-07
  • 使用Docker搭建Redis主从复制的集群

    使用Docker搭建Redis主从复制的集群

    这篇文章主要介绍了使用Docker搭建Redis主从复制的集群,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-07-07
  • docker打包Python环境的过程详解

    docker打包Python环境的过程详解

    这篇文章主要介绍了docker打包Python环境过程,准备工作需要大家复制python程序启动程序,具体操作流程跟随小编一起看看吧
    2021-08-08
  • 聊聊Docker不适合跑 MySQL 的N个原因

    聊聊Docker不适合跑 MySQL 的N个原因

    容器是为了解决“在切换运行环境时,如何保证软件能够正常运行”这一问题,这篇文章主要介绍了Docker 为什么不适合跑 MySQL?有N个原因,需要的朋友可以参考下
    2022-12-12
  • 聊聊docker跨主机之间容器通信问题

    聊聊docker跨主机之间容器通信问题

    这篇文章主要介绍了docker跨主机之间容器通信问题,创建网桥之后,使用ifconfig查看会多出一个网桥,该网桥在docker启动或者重启之后,会自动显示出来,具体实践跟随小编一起看看吧
    2022-05-05
  • docker 部署 Elasticsearch kibana及ik分词器详解

    docker 部署 Elasticsearch kibana及ik分词器详解

    这篇文章主要介绍了docker 部署 Elasticsearch kibana及ik分词器详解,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-05-05
  • docker在Linux环境下的安装教程

    docker在Linux环境下的安装教程

    这篇文章主要介绍了docker在Linux环境下的安装教程,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-11-11

最新评论