Home  >  Q&A  >  body text

dockerfile - 为什么docker容器启动不了?

sudo docker run -d centos /bin/bash创建容器之后,使用docker ps -a 发现容器已经停止,再使用docker start id 启动容器之后,观察ps -a 的操作时间,发现容器其实已经启动过,但是马上就停止了。这是什么原因?

补充:尝试三种镜像的启动,centos,mysql,nginx,结果只有nginx能启动。其他两个怎么也启动不了。

补充二:问题基本已经找到了,原因就是:Docker容器后台运行,就必须有一个前台进程。主线程结束,容器会退出。
sudo docker run -d centos 改成 sudo docker -dit centos 就行了。
总感觉有点别扭,大家还有更好的解决办法吗?望大家指教。。。

世界只因有你世界只因有你2707 days ago797

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-04-25 09:05:07

    sudo docker run -t -i centos /bin/bash

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-04-25 09:05:07

    You can view the output of the container main program through the docker logs container ID. Try to analyze the reason through this.

    In addition, the default startup of the system image is bash. If the input stream is not connected, it will end immediately.

    reply
    0
  • Cancelreply