docker Container is not running

参考链接:https://stackoverflow.com/questions/29599632/docker-container-is-not-running/49204476

1、

Container 79b3fa70b51d seems to only do an echo.

That means it starts, echo and then exits immediately.

The next docker exec command wouldn't find it running in order to attach itself to that container and execute any command: it is too late. The container has already exited.

The docker exec command runs a new command in a running container.

The command started using docker exec will only run while the container's primary process (PID 1) is running

2、

docker run -d  -v /app:/var/www/swoft --name swoft swoft/swoft // 开发环境和容器进行关联
docker run -d --entrypoint="" -v /app:/var/www/swoft --name swoft swoft/swoft bash // 开发环境和容器进行关联
docker ps -a
docker exec -it swoft bash 

3、参考链接:https://segmentfault.com/a/1190000010940432

1.容器的生命周期。要把docer容器看做是一个单独的进程及运行环境。容器不等价于一个虚拟的操作系统。Docker的开发人员也一直主张doder容器应该只运行一个进程。例如,一个web server服务就是一个进程。docker run命令就是为了运行一个进程。当一个进程结束了,那么docker容器也就结束了。

2.根据问题中描述的现象,两条命令的差别就在与末尾是否添加了/bin/bash这条command。暂且先停住。我们回过头来看docker image是怎么生成的。

3.Dockerfile文件。Dockerfile文件中有两个关键字CMDENTRYPOINT。其中CMD的值是可以被覆盖的。举个栗子:
假设Dockerfile中的内容包含了:

FROM python
CMD ["/home/hello.sh","Hello World"]   
ENTRYPOINT ["/home/hello.sh","xiaoming"]

那么根据CMD可被覆盖的特征来看,如果在docker run后增加了/bin/bash。那么,在镜像run的时候,执行的CMD就变成了/bin/bash。一般镜像文件中两种关键字选用其中之一就可以了。但也可以同时使用。同时使用的时候,CMD中的值会被当作ENTRYPOINT的参数。所以,ENTRYPOINT的内容就变成["/home/hello.sh","/bin/bash"]

4.我们再来看我要启动的registry镜像中都包含了哪些CMD和ENTRYPOINT。如下图:
图片描述

根据上图中的前两行可知,容器运行后默认执行的是/entrypoint.sh脚本,脚本命令的参数是/etc/docker/regis...。所以,如果我们自己在run的时候添加了新的command,那么镜像内置的执行命令就无法正确执行了,于是容器就Exited了。

原文地址:https://www.cnblogs.com/cbugs/p/12215481.html