- pm2-runtime designed for Docker container which keeps an application in the foreground which keep the container running.
- pm2 is designed for normal usage where you send or run the application in the background.
例子:
Dockerfile
FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
CMD [ "pm2", "start","/app/server.js"]
这种情况容器会在刚启动的时候就挂掉。
为了解决这个问题,可以使用 pm2-runtime
FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
ENV NODE_ENV=development
CMD [ "pm2-runtime", "start","/app/bin/www"]
参考链接:
官方文档:https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/
stack overflow:https://stackoverflow.com/questions/53962776/whats-the-difference-between-pm2-and-pm2-runtime