Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker CMD with environment variable while running node application

I need to pass an environment variable to node like below.

RAZZLE_ENV=production node build/server.js

How I can achieve this with docker CMD command. My current config is like this:

CMD [ 'node', 'build/server.js' ]

I did change it to this:

CMD [ 'RAZZLE_ENV=production node', 'build/server.js' ]

But it does not work as expected and the container is not going to be created even.

UPDATE: the error is:

Cannot find module /app/RAZZLE_ENV=production node
like image 927
sadrzadehsina Avatar asked Sep 15 '26 16:09

sadrzadehsina


1 Answers

Dockerfile

# Use ARG so that it can be overridden at build time 
ARG ARG_RAZZLE_ENV=development

# Set environment variable based on ARG
ENV RAZZLE_ENV=$ARG_RAZZLE_ENV

CMD [ 'node', 'build/server.js' ]

Pass ARG during build:

docker build --build-arg ARG_RAZZLE_ENV=production . -t name:tag

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!