alexcdev1 il y a 6 mois
Parent
commit
e88001558a
1 fichiers modifiés avec 9 ajouts et 4 suppressions
  1. 9 4
      Dockerfile.prod

+ 9 - 4
Dockerfile.prod

@@ -1,5 +1,5 @@
 # Install dependencies only when needed
-FROM node:alpine AS deps
+FROM node:18-alpine AS deps
 # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
 RUN apk add --no-cache libc6-compat
 RUN npm install -g pnpm
@@ -13,7 +13,7 @@ COPY package.json pnpm-lock.yaml* .npmrc* ./
 RUN pnpm install --frozen-lockfile
 
 # Rebuild the source code only when needed
-FROM node:alpine AS builder
+FROM node:18-alpine AS builder
 WORKDIR /app
 
 # 安装 pnpm
@@ -31,7 +31,7 @@ ENV MONGODB_URI=$MONGODB_URI
 RUN pnpm build
 
 # Production image, copy all the files and run next
-FROM node:alpine AS runner
+FROM node:18-alpine AS runner
 WORKDIR /app
 
 ENV NODE_ENV production
@@ -44,6 +44,7 @@ COPY --from=builder /app/public ./public
 COPY --from=builder /app/package.json ./package.json
 COPY --from=builder /app/node_modules ./node_modules
 COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
+COPY --from=builder /app/next.config.js ./next.config.js
 
 USER nextjs
 
@@ -52,4 +53,8 @@ EXPOSE 3000
 ENV PORT 3000
 ENV NEXT_TELEMETRY_DISABLED 1
 
-CMD ["node", "node_modules/.bin/next", "start"]
+# 安装 dos2unix 并修复可能的行结束符问题
+RUN apk add --no-cache dos2unix && dos2unix /app/node_modules/.bin/next
+
+# 使用 pnpm 启动应用
+CMD ["pnpm", "start"]