'nextjs + react-env: how to pass env variables from docker compose
I am using the https://github.com/andrewmclagan/react-env way to pass env variables to browser. I am able to do using .env file, but not through the docker compose
I have a docker compose file. I have to set the api url for the nextjs project
node_nextjs:
image: "node16_build_custom"
ports:
- 3000:3000
environment:
- DS_PATH=/home/simha/app/torsha_datasets
- REACT_APP_API_HOST=http://localhost:8000
volumes:
- type: bind
source: ../CODE/nextjs_frontend
target: /home/simha/app
command:
- sh
- -c
- |
id
yarn react-env
pm2-runtime npm -- start
stdin_open: true # Add this line into your service
tty: true # Add this line into your service
networks:
- nginx_network
I am setting the REACT_APP_API_HOST=http://localhost:8000 in the docker compose
but yarn react-env does not create the env variable inside public/__ENV.js
I see
window.__ENV = {};
How to pass the docker compose env varialbe inside .env file
i tried
.env
REACT_APP_API_HOST=$REACT_APP_API_HOST
This does not work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
