Search code examples
dockerdockerfilecontainers

Passing env variables at runtime without quotes


When passing environment during docker runtime, my environment variables are getting wrapped with quotes. How am I able to set an environment variable without having it quoted?

I set the environment like such; docker run server -e NODE_ENV=dev

Output from the command above:

node dist/server.js "NODE_ENV=dev"

Heres a snippet from my Dockerfile

FROM base AS release
# copy production node_modules
COPY --from=dependencies /root/app/prod_node_modules ./node_modules
# copy app sources
COPY . .
# expose port and define CMD
EXPOSE 3000
ENTRYPOINT ["npm", "run", "start:prod"]

Solution

  • First of all I think the sequence of your docker run command has a problem.

    -e option should be before your docker image name, like this

    docker run -e NODE_ENV=dev server
    

    If its still not helping, then try --env-file option of docker run.

    docker run --env-file /path/to/server.env server
    

    In server.env

    NODE_ENV=dev