0
votes

My NodeJs App was successfully deployed inside a Docker Container. I put this command in Dockerfile:

screen shot of pm2 docs

CMD ["pm2-runtime", "app.js"]

After restarting the app from the PM2 key metrics panel, the container disappeared (docker ps shows nothing) but strangely the app kept running. After a couple of minutes I figured out that pm2 was running it globally in the server. pm2 ls shows the app process.

Is this behaviour considered normal? Can this be prevented?

1

1 Answers

1
votes

This is not the expected behvour, there might be the case the same application is running on host with same keys, so by issue restart command can restart both process, but pm2 dashboard able to recognise the process even if it running against same keys.

What I assume, That after the restart from the dashboard there were some errors that kill the container and you were not able to see the container when you run docker ps, as pm2-runtime retires 3 times if there is any error occurs.

One way to double-check is to verify, run docker ps -a and grab the container id and check docker logs stopeed_container_id, you will probely see somethign like

2019-1-02T20:53:03: PM2 log: 0 application online, retry = 3
2019-1-02T20:53:05: PM2 log: 0 application online, retry = 2
2019-1-02T20:53:07: PM2 log: 0 application online, retry = 1
2019-1-02T20:53:09: PM2 log: 0 application online, retry = 0
2019-1-02T20:53:09: PM2 log: Stopping app:www id:0
2019-1-02T20:53:09: PM2 error: app=www id=0 does not have a pid
2019-1-02T20:53:09: PM2 log: PM2 successfully stopped

So overide this behour to do not stopped container even if there is error, I will not recomend this approch but You can run with --no-auto-exit flag.

--no-auto-exit             
do not exit if all processes are errored/stopped or 0 apps launched

pm2-runtime option

CMD pm2-runtime --no-auto-exit app.js