I have the docker image from keymetrics/pm2:8-jessie and running my nodejs application well with pm2. I tried to add pm2-logrotate for sizing the log with date. I added the following in my Dockerfile. The module pm2-logrotate can be started but the Target PID is null. Anyone can help please?
FROM keymetrics/pm2:8-jessie
RUN npm install
RUN pm2 install pm2-logrotate
RUN pm2 set pm2-logrotate:retain 90
RUN pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
RUN pm2 set pm2-logrotate:max_size 10M
RUN pm2 set pm2-logrotate:rotateInterval 0 0 * * *
RUN pm2 set pm2-logrotate:rotateModule true
RUN pm2 set pm2-logrotate:workerInterval 10
ENV NODE_ENV=$buildenv
ENV NPM_CONFIG_LOGLEVEL warn
CMD ["sh", "-c", "pm2-runtime start pm2.${NODE_ENV}.config.js"]
pm2 ls
┌──────────────┬────┬─────────┬─────────┬─────┬────────┬─────────┬────────┬─────┬────────────┬──────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────────┼────┼─────────┼─────────┼─────┼────────┼─────────┼────────┼─────┼────────────┼──────┼──────────┤
│ app_server │ 1 │ 1.0.0 │ cluster │ 150 │ online │ 1 │ 2h │ 0% │ 104.4 MB │ root │ disabled │
└──────────────┴────┴─────────┴─────────┴─────┴────────┴─────────┴────────┴─────┴────────────┴──────┴──────────┘
Module
┌───────────────┬────┬─────────┬─────┬────────┬─────────┬─────┬───────────┬──────┐
│ Module │ id │ version │ pid │ status │ restart │ cpu │ memory │ user │
├───────────────┼────┼─────────┼─────┼────────┼─────────┼─────┼───────────┼──────┤
│ pm2-logrotate │ 2 │ 2.7.0 │ 205 │ online │ 0 │ 0% │ 44.5 MB │ root │
└───────────────┴────┴─────────┴─────┴────────┴─────────┴─────┴───────────┴──────┘
One reason is as
pm2 logrotateis not the primary process of the Docker container, but a managed process by pm2, so you can verify this behaviour by stopping main process that is definedpm2.${NODE_ENV}.config.jsyour container will die no matter ifpm2-logrotateis running.Also, I do not think it should be null, it should be something like
Also will suggest to use the alpine base image as the above image seem very heavy, the below image is 150MB while the above image is arround 1GB.