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.

35 lines
648 B
Docker

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 阶段1: 构建阶段
FROM node:22.14.0-slim AS builder
WORKDIR /app
# 全局安装 pnpm
RUN npm install -g pnpm
# 复制依赖文件
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --registry https://registry.npmmirror.com
# 复制源码并构建
COPY . .
RUN pnpm run build
# 阶段2: 生产运行阶段
FROM node:22.14.0-slim
WORKDIR /app
# 全局安装 pnpm确保运行时可用
RUN npm install -g pnpm
# 从构建阶段复制所有文件(包括 node_modules 和构建产物)
COPY --from=builder /app .
# 设置环境变量
ENV PORT 3000
ENV NODE_ENV production
EXPOSE 3000
# 使用 pnpm 启动
CMD ["pnpm", "start"]