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

时间:2019-05-01 12:42:32

标签: node.js docker pm2

我的Dockerfile包含pm2 start命令,如下所示:

FROM node:10

WORKDIR /usr/src/app

COPY . .

# ...

EXPOSE 8080

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

但是,在成功启动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.

如何使容器保持与pm2一起运行?

1 个答案:

答案 0 :(得分:1)

问题是pm2 start将pm2作为守护程序运行,Docker并不知道。

您需要使用pm2-runtime使其在前台运行:

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

See pm2 "Container integration" docs.