web/Dockerfile
2025-05-31 23:04:31 +08:00

39 lines
834 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.

# 构建阶段
FROM node:20-alpine as build-stage
# 设置工作目录
WORKDIR /app
# 设置环境变量解决rollup和npm问题
ENV NPM_CONFIG_LEGACY_PEER_DEPS=true
ENV NPM_CONFIG_FUND=false
ENV NPM_CONFIG_AUDIT=false
# 复制package.json和package-lock.json
COPY package*.json ./
# 清理并安装依赖解决rollup问题
RUN rm -rf node_modules package-lock.json && \
npm install --legacy-peer-deps --no-fund --no-audit && \
npm rebuild
# 复制项目文件
COPY . .
# 构建应用
RUN npm run build
# 生产阶段
FROM nginx:stable-alpine as production-stage
# 将构建好的文件复制到nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 复制nginx配置文件
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露80端口
EXPOSE 80
# 启动nginx
CMD ["nginx", "-g", "daemon off;"]