I have a env variable name: REACT_APP_BACKEND in my react app. I'm able to build my app and run it successfully in nginx in my macos.
When I try to run it inside docker and nginx, I pass list of environment variables with --env-file=.env command. However this env variable is undefined in the browser, even though when I entered the running docker instance I'm able to echo this variable successfully.
/ # echo $REACT_APP_BACKEND
http://localhost:3000
/ #
I don't know if I missing somethings in docker settings, nginx settings or my build command?
This is the nginx settings (nginx.conf):
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
This is docker config:
#... installing node and npm install#
RUN npm run build
### STAGE 2: Production Environment ###
FROM nginx:1.12.0-alpine
COPY --from=build /usr/src/app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]