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 Runtime is a Production Process Manager for Node. js applications with a built-in Load Balancer. It allows you to keep applications alive forever, to reload them without downtime and facilitate common Devops tasks. Starting an application in production mode is as easy as: $ pm2 start app.js.
you may not be in favour of using pm2 inside Docker but sometimes the application requirements are different and you may need to run two nodejs application in one docker container, so in case if you want to run frontend and backend application in the same container then in the case pm2 work well then other workarounds.
PM2: A production process manager for Node. js applications that has a built-in load balancer. PM2 enables you to keep applications alive forever, reloads them without downtime, helps you to manage application logging, monitoring, and clustering.
PM2 is a production process manager for Node. js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Starting an application in production mode is as easy as: $ pm2 start app.js.
The main difference between pm2 and pm2-runtime is
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With