How to setup Node environment variable in Dockerfile for running node.js application?

djangogirl picture djangogirl · Mar 24, 2017 · Viewed 14.8k times · Source

Can anyone suggest how can I setup NODE_ENV variable in dockerfile when running a node app.

Answer

opHASnoNAME picture opHASnoNAME · Mar 24, 2017

There a two ways, while building the image or when running the container.

For builds:

Add to your Dockerfile

ENV NODE_ENV=whatEver

Or use build arguments if you don't want them to stick during runtime Docker build --build-args NODE_ENV whatEver

When running:

Run your container with "-e"

docker run -e NODE_ENV=whatever mycontainer