|
@@ -43,14 +43,17 @@
|
|
# CMD ["node_modules/.bin/next", "start"]
|
|
# CMD ["node_modules/.bin/next", "start"]
|
|
|
|
|
|
# Stage 1: Dependencies
|
|
# Stage 1: Dependencies
|
|
-FROM node:alpine AS deps
|
|
|
|
|
|
+FROM node:18-alpine AS deps
|
|
WORKDIR /app
|
|
WORKDIR /app
|
|
|
|
|
|
# 安装 pnpm
|
|
# 安装 pnpm
|
|
RUN npm install -g pnpm
|
|
RUN npm install -g pnpm
|
|
|
|
|
|
-# 安装 libc6-compat(如果需要的话)
|
|
|
|
-RUN apk add --no-cache libc6-compat
|
|
|
|
|
|
+# 安装 bash 和其他必要的工具
|
|
|
|
+RUN apk add --no-cache libc6-compat bash
|
|
|
|
+
|
|
|
|
+# 设置 pnpm 使用淘宝镜像
|
|
|
|
+RUN pnpm config set registry https://registry.npm.taobao.org
|
|
|
|
|
|
# 复制 package.json 和 pnpm-lock.yaml(如果有的话)
|
|
# 复制 package.json 和 pnpm-lock.yaml(如果有的话)
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
@@ -59,11 +62,12 @@ COPY package.json pnpm-lock.yaml* ./
|
|
RUN pnpm install --frozen-lockfile
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
|
|
# Stage 2: Builder
|
|
# Stage 2: Builder
|
|
-FROM node:alpine AS builder
|
|
|
|
|
|
+FROM node:18-alpine AS builder
|
|
WORKDIR /app
|
|
WORKDIR /app
|
|
|
|
|
|
-# 安装 pnpm
|
|
|
|
|
|
+# 安装 pnpm 和 bash
|
|
RUN npm install -g pnpm
|
|
RUN npm install -g pnpm
|
|
|
|
+RUN apk add --no-cache bash
|
|
|
|
|
|
# 复制所有文件
|
|
# 复制所有文件
|
|
COPY . .
|
|
COPY . .
|
|
@@ -75,11 +79,14 @@ COPY --from=deps /app/node_modules ./node_modules
|
|
RUN pnpm build
|
|
RUN pnpm build
|
|
|
|
|
|
# Stage 3: Runner
|
|
# Stage 3: Runner
|
|
-FROM node:alpine AS runner
|
|
|
|
|
|
+FROM node:18-alpine AS runner
|
|
WORKDIR /app
|
|
WORKDIR /app
|
|
|
|
|
|
ENV NODE_ENV production
|
|
ENV NODE_ENV production
|
|
|
|
|
|
|
|
+# 安装 bash
|
|
|
|
+RUN apk add --no-cache bash
|
|
|
|
+
|
|
# 创建非 root 用户
|
|
# 创建非 root 用户
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
@@ -98,8 +105,5 @@ EXPOSE 3000
|
|
|
|
|
|
ENV PORT 3000
|
|
ENV PORT 3000
|
|
|
|
|
|
-# 禁用 Next.js 遥测(如果需要)
|
|
|
|
-# ENV NEXT_TELEMETRY_DISABLED 1
|
|
|
|
-
|
|
|
|
-# 启动应用
|
|
|
|
-CMD ["pnpm", "start"]
|
|
|
|
|
|
+# 使用 bash 启动应用
|
|
|
|
+CMD ["/bin/bash", "-c", "node_modules/.bin/next start"]
|