diff --git a/Dockerfile b/Dockerfile index 1327d77..c95c735 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,17 @@ -# 🚀 超优化版 Dockerfile for Next.js with pnpm (目标: <200MB) +# 🚀 超优化版 Dockerfile for Next.js with pnpm (Ubuntu环境解决兼容性) # 第一阶段:构建阶段 -FROM node:22-alpine AS builder +FROM node:22-slim AS builder # 设置工作目录 WORKDIR /app +# 安装必要的系统依赖 +RUN apt-get update && apt-get install -y \ + python3 \ + make \ + g++ \ + && rm -rf /var/lib/apt/lists/* + # 安装 pnpm RUN npm install -g pnpm@9.15.0 @@ -30,20 +37,20 @@ RUN rm -rf node_modules && \ rm -rf /root/.pnpm-store && \ pnpm store prune -# 第二阶段:运行阶段 (使用更小的基础镜像) -FROM node:22-alpine AS runner +# 第二阶段:运行阶段 (使用Ubuntu slim镜像) +FROM node:22-slim AS runner # 设置工作目录 WORKDIR /app # 创建非root用户 -RUN addgroup --system --gid 1001 nodejs && \ - adduser --system --uid 1001 nextjs +RUN groupadd --system --gid 1001 nodejs && \ + useradd --system --uid 1001 --gid nodejs nextjs # 只安装必要的运行时工具 -RUN apk add --no-cache wget && \ - apk cache clean && \ - rm -rf /var/cache/apk/* +RUN apt-get update && apt-get install -y \ + wget \ + && rm -rf /var/lib/apt/lists/* # 从构建阶段复制构建产物 (standalone模式包含所有需要的依赖) COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./