You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
717 B
Docker
31 lines
717 B
Docker
# 构建阶段
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# 复制依赖清单
|
|
COPY package.json pnpm-lock.yaml ./
|
|
|
|
# 设置 npm 和 pnpm 使用国内镜像源(关键!)
|
|
RUN npm config set registry https://registry.npmmirror.com && \
|
|
npm install -g pnpm && \
|
|
pnpm config set registry https://registry.npmmirror.com
|
|
|
|
# 安装依赖(现在会走淘宝镜像)
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# 复制源码并构建
|
|
COPY . .
|
|
RUN pnpm run build:prod # 生成 dist-prod 目录
|
|
|
|
# 运行阶段
|
|
FROM nginx:alpine
|
|
|
|
# 复制前端产物
|
|
COPY --from=builder /app/dist-prod /usr/share/nginx/html
|
|
|
|
# 复制 Nginx 配置
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
|
|
EXPOSE 80
|
|
CMD ["nginx", "-g", "daemon off;"] |