我面临着一个奇怪的问题,我有这个.env
REACT_APP_URL=http://localhost:8080
REACT_APP_API_URL=http://localhost:4500/api
REACT_APP_VEHICLE_IMAGE_URL='URL'
REACT_APP_NAME=NAME
REACT_APP_GA_TRACKING_ID=
如果我使用npm start
运行应用程序,变量将被正确识别.
如果我还try 在本地运行docker构建,而不从docker集线器拉出映像,则变量可以正常工作.以下是命令:
docker build . -t container
docker run -p 8080:8080 --env-file .env -d --name container--restart always container
它们被识别,应用程序使用这些变量运行.
This is the dockerfile:
FROM node:16-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "npm", "run", "preview" ]
与此同时,每次我按下Master时,我都会在dockerHub中推送应用程序. 在这种情况下,变量无法识别:
docker pull user/repository_test
docker run -p 8080:8080 --env-file .env -d --name repo --restart always user/repository_test
变量没有被识别,这怎么可能呢?然而,我可以看到在判断中的docker中,变量在容器中传递,但在Reaction上未被识别.
在顶部的图像上,是来自 docker 的判断容器,其中环境变量不被识别,但它们存储在容器上.