3

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

this cannot set RAZZLE_ENV for runtime, need rebuild every time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.