title

Dotorimook's blog

Hello, World! This is Dotorimook's blog

    interest
  • HCI
  • UI/UX
  • Frontend
  • javascript
  • node

Categories

Tags

docker container에서 pm2가 시작하자마자 종료될 때

December 20, 2020

도커 컨테이너에서 pm2를 실행하는 데 바로 꺼질 때

node 프로젝트를 프로덕션 환경에 pm2로 올려보도록 한다. node docker image를 이용해서 docker container에서 pm2 start로 시작하도록 올려본다. 하지만 갑자기 시작하자마자 docker container가 종료된다. 분명 정확하게 프로세스기 실행되었는데.. 어찌된 일일까. 어떻게 해결할까?

결론부터 말하자면 pm2가 아니라 pm2-runtime을 이용하면 해결된다.

그러니까,

$pm2 start ecosystem.config.js

라고 되어있었다면,

$pm2-runtime start ecosystem.config.js

라고 해주면 된다.

이유는,

  • pm2: 일반적인 용도로 애플리케이션을 백그라운드에 보내고 실행함.
  • pm2-runtime: 도커 컨테이너에서 사용하는 용도로, 애플리케이션을 foreground에 유지하고 컨테이너를 계속 실행하게 함.

이라고 한다.

문서에 따르면,

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.

reference

  1. stackOverflow