I need to exec or discard
CMD [“node”, “appNodejs/server.js”]
command depending on env file params. I didn’t find out how to get it with Dockerfile, so I check env file inside my server.js and do
process.exit(0)
if node server isn’t required. But docker continuously restarting server.js and i’m getting:
app_php_1 exited with code 0
app_php_1 exited with code 0
app_php_1 exited with code 0
app_php_1 exited with code 0
app_php_1 exited with code 0
app_php_1 exited with code 0
app_php_1 exited with code 0
I think it’s because of volumes are attached after CMD [“node”, “appNodejs/server.js”] - how to fix it?
How to terminate node process so it wouldn’t be starting again?
Hi, volumes are attached “on boot”, so it will be there when the CMD is exectuted, but, it could be the “:cached” in your volume mount, try and remove that part.
Is restarted because you made it as a service, so docker will continue to try to get your container up and running, also becaues you defined: restart: always
And it exits because of the error you mentioned.
In the docker/php/Dockerfile I want to start php-fpm as main service. But CMD [“node”, “appNodejs/server.js”] should or should not starting based on my env file. So I need something like this:
FROM php:7.1-fpm
WORKDIR /var/www
# here I want to start php-fpm as it my main service
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& apt-get install nodejs -yq
# start nodejs app by condition only
if (condition) {
CMD ["node", "appNodejs/server.js"]
}
I didn’t find how to add if statement like this in dockerfile, so maybe terminating server.js inside itself is workaround.
Okay, the best way to do this, would be to create a custom start script.
So you in the start shell script check what process should be run and execute.
yes it is, like you create a bash script in /startup.sh, and in that you check and and execute what you need.
and then define /startup.sh as the entrypoint