andrewmclagan/react-env

how to pass env variables from docker compose

Closed this issue · 2 comments

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.

Sorry not 100% sure, although it's likely to do with your command. Look at the example package json commands:

https://github.com/andrewmclagan/react-env/blob/master/examples/next.js/package.json

Also if you read the docs there is a mention of entrypoints https://github.com/andrewmclagan/react-env#using-with-docker-entrypoint which is better then an interpolated command.