There is plenty of documentation and dicussion regarding running pm2 inside a Docker container. And general consensus seems that you use K8 or docker-compose to handle health checking/auto-restarts/multi-instancing & load balancing (in combination with nginx) ie- instead of pm2, and if you need pm2 ie- to manage multiple node processes in a single container that is the extent to which you would use it; in a single container context if anything.

Yet pm2 has an excellent multi-env conditional loader tek aka 'ecosystem file' which as a NodeJS dev I find more intuitive and flexible than a docker-compose.yml config file.

My question is, is it practical to run docker-compose via pm2 ?

That way you need store only a minimal amount of hardcoded values in your docker-compose.yml and can instead frontload vars via env vars that you define in pm2.

And to launch your app in production for example you could do:

pm2 start ecosystem.config.js --only myapp-production-config --env production

...where the primary script value of your ecosystem config is the docker-compose binary with args: up.

Or is there any reason launching docker-compose via a process manager like pm2 a no-no ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.