Currently I am using an nginx image, and was trying to start pm2 in background inside the nginx container (company's cloud infra is oriented around single docker containers).
I like using the nginx image as nginx seems to be very sensitive around permissions and user roles etc. I'm also not adding a CMD or ENTRYPOINT - I'm letting the nginx official image's default ENTRYPOINT run.
That entrypoint will run scripts that appear in the /docker-entrypoint.d/ directory.
So when I'm building my nginx-based docker image, I can add a script into /docker-entrypoint.d/40-start-node-server.sh and the nginx image will call this shell script when the server is starting up.
My script is:
echo "start pm2";
cd /mf-core/;
IS_DOCKER=1 PORT=2227 ./node_modules/.bin/pm2-runtime start ./ecosystem.config.cjs --env production &
echo "pm2 running in background";
cd /;
I was struggling with getting logs to appear in stdout (so I can easily work on the app locally) but this seems to be working.
In addition, the ./node_modules/.bin/pm2-runtime is nice because I get the latest snapshot from my package-lock.json, so won't un-expectedly pickup new code on any given production deploy.
Currently I am using an nginx image, and was trying to start pm2 in background inside the nginx container (company's cloud infra is oriented around single docker containers).
I like using the nginx image as nginx seems to be very sensitive around permissions and user roles etc. I'm also not adding a CMD or ENTRYPOINT - I'm letting the nginx official image's default ENTRYPOINT run.
That entrypoint will run scripts that appear in the
/docker-entrypoint.d/
directory.So when I'm building my nginx-based docker image, I can add a script into
/docker-entrypoint.d/40-start-node-server.sh
and the nginx image will call this shell script when the server is starting up.My script is:
I was struggling with getting logs to appear in stdout (so I can easily work on the app locally) but this seems to be working.
In addition, the
./node_modules/.bin/pm2-runtime
is nice because I get the latest snapshot from my package-lock.json, so won't un-expectedly pickup new code on any given production deploy.