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

后端 未结 1 429
遥遥无期
遥遥无期 2021-01-01 16:51

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 pro

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 17:23

    The main difference between pm2 and pm2-runtime is

    • 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.

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

    For example

    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.

    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"]
    

    As the container keeps running and it allocates tty session.

    From the documentation

    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

    0 讨论(0)
提交回复
热议问题