Pass variable to .env file at Elastic Beanstalk for dockerized Reactjs app

0

Hi,

I have React app running at EB with docker and nginx. I have .env like REACT_APP_API_BASE_URL=${ADMIN_BACKEND_API} REACT_APP_SIGNUP_ENDPOINT=$REACT_APP_API_BASE_URL/api/v1/auth/signup

Also my Dockerfile is: `FROM node:17.1-alpine as build-stage WORKDIR /app COPY package*.json ./ RUN npm install COPY . .

RUN npm run build:production

FROM nginx:1.22.1-alpine as prod-stage COPY --from=build-stage /app/build /usr/share/nginx/html COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]`

I confgured ADMIN_BACKEND_API at AWS Beanstalk console. I assume it will be passed to .env and sibstitute REACT_APP_API_BASE_URL=${ADMIN_BACKEND_API} when I run eb deploy, but it does not. How can I do that?

Kirill
已提問 8 個月前檢視次數 262 次
1 個回答
1
已接受的答案

Hello, hope you are doing good. In case of using ElasticBeanstalk Docker platform it is suggested to pass your environment variables for containers either via .env file or if you are using docker-compose.yml file then you can define the environment variables in the docker-compose file. If you are using the Docker Compose tool on the Amazon Linux 2 Docker platform, Elastic Beanstalk generates a Docker Compose environment file called .env in the root directory of your application project. This file stores the environment variables you configured for Elastic Beanstalk.If you include a .env file in your application bundle, Elastic Beanstalk will not generate an .env file. For more information, check out this documentation : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-env-cfg.env-variables

Now you can consider using either of these two scenarios(defining env variables in docker-compose or using the .env file in your source bundle) to get the environment variables and retrieve environment variables from the .env file. One way to get environment variables defined in .env file is mentioned here : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-env-cfg.env-variables

AWS
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南