Docker-compose 环境变量似乎根本没有设置。我曾尝试使用 env_file 和 environment 字段,但是在我的 vue 应用程序中打印 process.env 时,唯一可见的变量是 NODE_ENV 和 BASE_URL
这是我的 docker-compose 代码:
frontend:
container_name: "Frontend"
build:
context: .
dockerfile: frontend.dockerfile
env_file:
- ./frontend.env
environment:
VUE_APP_BACKEND_URL: "django"
ports:
- 8000:80
command: echo $VUE_APP_BACKEND_URL
Run Code Online (Sandbox Code Playgroud)
前端 Dockerfile:
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY ./front/package*.json ./
RUN npm install
COPY ./front .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Run Code Online (Sandbox Code Playgroud)
我的 frontend.env …