footprint/frontend/Dockerfile

35 lines
714 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 前端 Dockerfile - 多阶段构建
FROM node:18-alpine as build
WORKDIR /app
# 复制package文件
COPY package*.json ./
# 安装依赖(使用 install 而不是 ci允许更新 lock 文件)
RUN npm install --legacy-peer-deps
# 复制源代码
COPY . .
# 构建时传入环境变量(不设置默认值,从 docker-compose 传入)
ARG REACT_APP_API_URL
ENV REACT_APP_API_URL=$REACT_APP_API_URL
# 构建应用
RUN npm run build
# 生产阶段 - 使用nginx服务静态文件
FROM nginx:alpine
# 复制构建产物
COPY --from=build /app/build /usr/share/nginx/html
# 复制nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]