2

Is it better to run N docker containers or pm2 with N instances? What approach is more efficient from resources utilization (cpu/memory) point of view?

Update: I don't ask how to run node.js app using pm2 in a docker container. I want to understand what is a better setup if we talk about single instance server, run app in a multiple docker containers or in multiple threads using pm2.

Eugene Manuilov
  • 4,271
  • 8
  • 32
  • 48
  • It depends on a lot of different factors. One containerizes the applications, the other manages processes within a single, non-containerized context. If CPU/memory is your **only** concern I would plainly expect PM2 to win because it doesn't have containerization overhead, but I also don't think you should boil down the differences to just CPU/memory. – zero298 Feb 15 '19 at 16:03
  • And arguably, you could use pm2 to run N docker containers, or run a docker container with pm2 running N instances as well. :D – Paul Feb 15 '19 at 16:05
  • Possible duplicate of [Should I use forever/pm2 within a (Docker) container?](https://stackoverflow.com/questions/28942614/should-i-use-forever-pm2-within-a-docker-container) – David Maze Feb 15 '19 at 18:17
  • 1
    @DavidMaze please, read carefully. If my question contains `pm2` and `docker container` words, then it doesn't mean that i want to run one inside of another one. – Eugene Manuilov Feb 15 '19 at 20:26

1 Answers1

0

There are different approaches to accomplish this, I would use a load balancer like Nginx and whatever you decide Docker containers running locally or system services, take a look at these articles:

  1. Nginx + Docker: https://auth0.com/blog/load-balancing-nodejs-applications-with-nginx-and-docker/

  2. Nginx + systemd: https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/ https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/

first part explains how to configure your app as a systemd service and the second how to launch multiple processes

edsadr
  • 1,087
  • 6
  • 17