patternjavascriptdockerMinor
Docker Container always stopped and started
Viewed 0 times
startedcontainerdockerstoppedalwaysand
Problem
I am using docker compose to build two containers, one is nodejs with pm2 and another is nginx.
The nginx one runs well but the nodejs with pm2 one keeps restarting: it runs for one second, then stops for ~10 seconds, then starts again and runs for one second, as you can see this is the output of
I have used
Using
This is the content of my Dockerfile:
If any of you could help me, I will update this question if you guys have any request.
Thank you
The nginx one runs well but the nodejs with pm2 one keeps restarting: it runs for one second, then stops for ~10 seconds, then starts again and runs for one second, as you can see this is the output of
docker ps -a:I have used
docker attach 'ID' but it still restarted.Using
docker logs shows nothing, but jenkins says that pm2 was started successfully:This is the content of my Dockerfile:
FROM node:8
MAINTAINER test
RUN npm install -g pm2
WORKDIR /var/www/marketing
EXPOSE 80
RUN npm install
RUN pm2 start npm -- stageIf any of you could help me, I will update this question if you guys have any request.
Thank you
Solution
You should keep at least one service running in foreground to keep the container running, you can do that using
You can also use a docker image for pm2 from docker hub, that will save your time and you can check the Dockerfile for it to see how it is written.
Check the keymetrics/pm2-docker-alpine project, for example.
ENTRYPOINT or CMD or both. For more info check Dockerfile: ENTRYPOINT vs CMD.You can also use a docker image for pm2 from docker hub, that will save your time and you can check the Dockerfile for it to see how it is written.
Check the keymetrics/pm2-docker-alpine project, for example.
Context
StackExchange DevOps Q#2297, answer score: 6
Revisions (0)
No revisions yet.