[英]cannot pm2 list in docker containers
I build a Docker image with Node.js and pm2. 我用Node.js和pm2构建了一个Docker镜像。 I started the container with:
我启动了容器:
docker run -d --name test -p 22 myImage
Then I go inside the container with: 然后我进入容器内:
docker exec -it test /bin/bash
In the container, exec the command: 在容器中,执行命令:
pm2 list
And it stuck here: 它停留在这里:
Ps: My application works well in the Docker container, if I add CMD pm2 start app.js
in the Dockerfile
. Ps:如果我在
Dockerfile
添加CMD pm2 start app.js
Dockerfile
CMD pm2 start app.js
,我的应用程序在Docker容器中运行良好。
If your dockerfile CMD is a pm2 command, you have you include --no-daemon arg option so pm2 runs in the foreground and so your docker container continues to run. 如果您的dockerfile CMD是pm2命令,那么您需要包含--no-daemon arg选项,以便pm2在前台运行,因此您的docker容器继续运行。
An example Dockerfile CMD: Dockerfile CMD示例:
CMD ["pm2", "start", "app.js", "--no-daemon"]
Otherwise, without --no-daemon, pm2 launches as a background process and docker thinks the execution of the pm2 command is done running and stops. 否则,如果没有--no-daemon,pm2将作为后台进程启动,而docker认为pm2命令的执行已完成并且已停止。
See https://github.com/Unitech/PM2/issues/259 请参阅https://github.com/Unitech/PM2/issues/259
CMD ["pm2-docker", "pm2.yaml"]
This is the new approach. 这是新方法。
Please do not use previous approaches. 请不要使用以前的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.