I have a Docker container that host a NodeJS Web application.
This docker container has the environment variable NODE_ENV=production
When I run the container, npm install skip all the devDependencies
from the package.json
file because of that.
I thought 3 differents solutions but none seems good
build
on my CVSChoice 1 take storage on CVS, and look stupid
Choice 2 require to have NodeJS, npm, gulp and many other libs installed
Choice 3 Looks the best
But i am interested in any others suggestions
Another solution to these sorts of situations is passing NODE_ENV as a build argument:
docker build --build-arg NODE=development --rm -t some/name .
For anyone running into issues passing NODE_ENV as a build-arg...try just passing it as NODE (as is done above) or some other name, instead. And in your Dockerfile you can use it like so:
ARG NODE=production
ENV NODE_ENV ${NODE}
RUN npm start
Note, in the code above, production
is the default, but you can override it with --build-arg NODE=development
.
My node APP in production require the env var NODE_ENV=production
So I've edited the docker file and removed the line
ENV NODE_ENV production
I've updated CMD to
CMD ['./start.sh']
Here is the ./start.sh
#!/bin/bash
gulp build
export NODE_ENV=production
nodemon server -p80
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