reactjs - 使用 docker compose 的 ReactJS 环境变量
问题描述
这是我的 reactjs 前端 docker compose 部分,我在其中添加了 2 个环境变量。创建的变量在反应应用程序中不可用,但我看到该变量是在前端 docker 容器内创建的。有没有办法解决这个问题?
反应 Docker 撰写
webapp:
image: webapp:latest
build:
context: ./webapp
dockerfile: Dockerfile
volumes:
- ./webapp:/app/webapp
- node-modules:/app/webapp/node_modules
ports:
- "3000:3000"
environment:
- REACT_APP_ASPNETCORE_URL=localhost:5000
- REACT_APP_ASPNETCORE_ENVIRONMENT=production
depends_on:
- dockerapi
networks:
- dockerapi-dev
我的 Docker 文件
#stage1 - build react app
FROM node:14.15.1 as build
# set the working direction
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package*.json ./
COPY yarn*.lock ./
RUN yarn --silent
COPY . /app
RUN yarn build
# stage 2 - build the final image and copy the react build files
FROM nginx:1.17.8-alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
使用命令“docker exec entryexit_webapp_1 env”反应容器环境变量
但是当我打开应用程序并转到网络详细信息时,没有设置环境变量
解决方案
推荐阅读
- cobol - 如果用户在 COBOL 中输入输入文件中的十进制值
- forms - 单击文本字段时,颤动键盘会隐藏自己
- c++ - 一个痛苦的错误 - codegen.cpp 中的 LoadInst 错误
- python - 如何加快涉及熊猫前一行的计算?
- javascript - 在表格中的特定行之后插入新行
- mediastore - 图像保存在 Scoped Storage Android 10 中,未出现在图库中
- kubernetes - 将 yaml(作为数据)放入配置映射中
- flutter - 如何在 Flutter 中突出显示特定字母的文本?
- django - 访问 XMLHttpRequest 在。从原产地。已被 CORS 策略阻止:不存在“Access-Control-Allow-Origin”标头
- python - Python每组插入连续数字