Docker在启动时退出CMD [英] Docker exits CMD on start
问题描述
我有一个运行 play Web应用程序的docker映像.在dockerfile中,有CMD启动服务器,它等待直到您按Ctrl + D退出.如果我这样做:
I have a docker image that runs play web application. In dockerfile there is CMD which starts the server and it waits until you hit Ctrl+D to exit. If I do:
docker run -d -i -v
它正常工作-启动服务器并等待ctrl + D.
It works correctly - starts the server and waits for ctrl+D.
但是,当我启动容器时情况并非如此:
This is however not the case when i start the container:
docker start -i
相反,服务器会自动停止:
Instead the server automatically stops:
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
[success] Total time: 1 s, completed Jul 27, 2016 11:54:13 AM <--- this indicates that the server was stopped.
如何强制Docker启动不停止服务器?
How can I force docker start to not stop server?
推荐答案
泊坞窗容器在其主进程完成时退出.在不了解您的docker-file(我没有使用play框架的经验)的情况下,您需要确保至少有一个进程保持活动状态.
A docker container exits when its main process finishes. Without having an insight into your docker-file (I have no experience with the play framework), you need to make sure that at least one process stays alive.
您有两种选择:
- Docker Way
尝试像docker run -it <your framework image> bash
一样使用-it
进入要启动的容器.这样可以使您的窗口保持打开状态,并允许您在容器中运行命令. - Docker调试"方式
尝试使用docker inspect <your container>
(使用docker ps -a
查找您的容器)命令来调查容器退出的原因.如果您有一个像start.sh这样的启动脚本,则可以尝试添加while true; do sleep 1000;
done以使容器保持运行状态,以调查退出之前容器在做什么. - 尝试使用已发布的docker映像之一,例如- https://hub. docker.com/r/ingensi/play-framework/
- Docker Way
Try using-it
likedocker run -it <your framework image> bash
to get into the container you are starting. This should keep your window open and allow you to run commands in the container. - Docker "debug" way
Try using thedocker inspect <your container>
(usedocker ps -a
to find your container) command to investigate why the container exited. In case you have a start script like start.sh you can try to addwhile true; do sleep 1000;
done to keep the container up to investigate on what it was doing before it exited. - Try using the one of the published docker images like - https://hub.docker.com/r/ingensi/play-framework/
P.S.我不能感到您是Docker新手,并且正在混用docker start
和docker run
命令.
P.S. I can not loose the feeling that you are new to docker and are mixing the docker start
and the docker run
command.
这篇关于Docker在启动时退出CMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!