我一直在将一些在同一台机器上执行的项目转移给每个单独的 docker。我试过使用 pm2
在这些 docker 项目之一上确保服务会在出现问题时重新启动(这是一个易变的项目),并且一些示例要求 Dockerfile 使用 pm2-runtime
而不是 pm2
.我一直在寻找这两者的差异,但找不到具体的东西,有人可以帮忙吗?
最佳答案
pm2 和 pm2-runtime 之间的主要区别是
简单来说,容器的生命周期就是
CMD
的生命周期。或 entrypoint
.例如
文件
FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
CMD [ "pm2", "start","/app/server.js"]
在这种情况下,容器将在运行该进程后立即死亡。
为了解决这个问题,你有 pm2 运行时
FROM node:alpine
RUN npm install pm2 -g
COPY . /app
WORKDIR /app
ENV NODE_ENV=development
CMD [ "pm2-runtime", "start","/app/bin/www"]
随着容器继续运行并分配 tty session 。
从文档
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
关于docker - pm2 和 pm2-runtime 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53962776/