React enviroment variables inside docker container not working

Viewed 17

I have an issue, where inside my docker container of the react app, my env variables are not working (got undefined).

My Dockerfile:

FROM <my nginx image>

COPY build/. /usr/share/nginx/html

COPY config/nginx.conf /etc/nginx/nginx.conf

EXPOSE 8080 80

My .env file (in the root of the project):

REACT_APP_VAR=HELLO

And in my code, I access that env variable through process.env.REACT_APP_VAR.

However, when I execute inside my production Linux server the command docker exec client -e, I do get all the env variables, including REACT_APP_VAR, PATH, HOSTNAME and etc.

Important to say, this issue is only in the docker (in the prod server), in my windows development station it works fine (without docker).

Also, I can't add ENV inside my Dockerfile, and I rather not use the docker yaml's files.

0 Answers
Related