pm2 和 pm2-runtime 有什么区别?

What's the difference between pm2 and pm2-runtime?

我一直在将一些在同一台机器上执行的项目转移到每个单独的 docker 中。我尝试在其中一个 docker 项目上使用 pm2 以确保在出现问题时服务会重新启动(这是一个不稳定的项目)并且一些示例要求 Dockerfile 使用 pm2-runtime 而不是 pm2。我一直在寻找这两者的区别,但我找不到具体的东西,有人可以帮忙吗?

pm2和pm2-运行时间的主要区别是

  • pm2-运行time designed for Docker container which keeps an application in the foreground which keep the container 运行ning,
  • pm2 专为在后台发送或 运行 应用程序的正常使用而设计。

简单来说,容器的生命就是CMDentrypoint的生命。

例如

Docker文件

FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
CMD [ "pm2", "start","/app/server.js"]

在这种情况下,容器会在 运行 进程结束后立即死亡。

为了解决这个问题,你有 pm2-运行time

FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
ENV NODE_ENV=development
CMD [ "pm2-runtime", "start","/app/bin/www"]

因为容器保持 运行ning 并且它分配 tty 会话。

来自文档

The goal of pm2-runtime is to wrap your applications into a proper Node.js production environment. It solves major issues when running Node.js applications inside a container like:

Second Process Fallback for High Application Reliability Process Flow Control Automatic Application Monitoring to keep it always sane and high performing Automatic Source Map Discovery and Resolving Support Further than that, using PM2 as a layer between the container and the application brings PM2 powerful features like application declaration file, customizable log system and other great features to manage your Node.js application in production environment.

docker-pm2-nodejs