简体   繁体   English

使用 pm2 start 时 Docker 以代码 0 退出

[英]Docker exits with code 0 when using pm2 start

My Dockerfile contains the pm2 start command as follows:我的Dockerfile包含 pm2 pm2 start命令,如下所示:

FROM node:10

WORKDIR /usr/src/app

COPY . .

# ...

EXPOSE 8080

CMD [ "pm2", "start", "npm", "--", "start" ]

However the container exits straightaway after pm2 logs successfully starting:然而,容器在 pm2 日志成功启动后立即退出:

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.

How can I get the container to stay running with pm2?如何让容器与 pm2 一起运行?

The problem is that pm2 start runs pm2 as a daemon ("in the background"), which Docker isn't aware of.问题是pm2 start将 pm2 作为守护进程运行(“在后台”),而 Docker 并不知道这一点。

You need to use pm2-runtime to make it run in the foreground:您需要使用pm2-runtime使其在前台运行:

CMD [ "pm2-runtime", "start", "npm", "--", "start" ]

See pm2 "Container integration" docs.请参阅 pm2“容器集成”文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM