pm2 和 pm2-runtime 有什么区别? [英] What's the difference between pm2 and pm2-runtime?

查看:122
本文介绍了pm2 和 pm2-runtime 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been transferring some projects that have been executing on the same machine to individual dockers each. I've tried to use pm2 on one of these docker projects to make sure the service would restart if something go wrong (it's a volatile project) and some of the examples demands the Dockerfile to use pm2-runtime instead of pm2. I've been searching for the differences of these two but I couldn't find something specific, could someone help?

推荐答案

pm2 和 pm2-runtime 的主要区别是

The main difference between pm2 and pm2-runtime is

  • pm2-runtime 专为 Docker 容器设计,将应用程序保持在前台,使容器保持运行,
  • pm2 专为您在后台发送或运行应用程序的正常使用而设计.

简单来说,容器的生命周期就是CMDentrypoint的生​​命周期.

In simple words, the life of the container is the life of CMD or entrypoint.

例如

Dockerfile

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

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

In this case, the container will die as soon as it run the process.

为了解决这个问题,你有pm2-runtime

To deal with this, you have 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"]

当容器继续运行并分配 tty 会话时.

As the container keeps running and it allocates tty session.

来自文档

pm2-runtime 的目标是将你的应用程序包装成一个合适的Node.js 生产环境.它解决了运行时的主要问题容器内的 Node.js 应用程序,例如:

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:

高应用程序可靠性流程的第二个流程回退控制自动应用程序监控以使其始终保持清醒和高性能自动源映射发现和解析支持更进一步,使用 PM2 作为容器和应用程序带来了 PM2 强大的功能,如应用程序声明文件、可定制的日志系统和其他强大的功能来管理您的生产环境中的 Node.js 应用.

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

这篇关于pm2 和 pm2-runtime 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆