I am trying to use below code below code in nodejs
if (process.env.NODE_ENV !== 'production')
I tried to set NODE_ENV variable from docker file like below.
FROM collinestes/docker-node-oracle:10-slim
ENV NODE_ENV=production
EXPOSE 8085
CMD ["npm","start"]
If i to run my docker image it does not start and throws error. If i remove NODE_ENV all runs fine. Is it the right way to setting NODE_ENV from dockerfile?
Remove the equal sign
ENV NODE_ENV production
Your Dockerfile should work, are you sure there isn't anything else inside the application, maybe package.json could be override it ?
I have tested it and it works correctly
$ echo $NODE_ENV
production
Also I would suggest to set the NODE_ENV variable while running the container as it would be easier to modify, I am aware that you can override it anyway if needed but setting it on the run-time will make your image with less layers. you can use the command below
-e can be used to pass an environment variable and can be passed multiple times if you have more than one variable
docker run -e NODE_ENV=production $IMAGENAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With