Dockerfile.prod 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Install dependencies only when needed
  2. FROM node:alpine AS deps
  3. # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
  4. RUN apk add --no-cache libc6-compat
  5. RUN npm install -g pnpm
  6. WORKDIR /app
  7. # COPY package.json yarn.lock ./
  8. COPY .env.local .env.local
  9. COPY .npmrc .npmrc
  10. RUN pnpm install
  11. # Rebuild the source code only when needed
  12. FROM node:alpine AS builder
  13. WORKDIR /app
  14. # 添加这行
  15. ARG MONGODB_URI
  16. ENV MONGODB_URI=$MONGODB_URI
  17. COPY . .
  18. COPY --from=deps /app/node_modules ./node_modules
  19. RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
  20. # Production image, copy all the files and run next
  21. FROM node:alpine AS runner
  22. WORKDIR /app
  23. ENV NODE_ENV production
  24. RUN addgroup -g 1001 -S nodejs
  25. RUN adduser -S nextjs -u 1001
  26. # You only need to copy next.config.js if you are NOT using the default configuration
  27. # COPY --from=builder /app/next.config.js ./
  28. COPY --from=builder /app/public ./public
  29. COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
  30. COPY --from=builder /app/node_modules ./node_modules
  31. COPY --from=builder /app/package.json ./package.json
  32. USER nextjs
  33. EXPOSE 3000
  34. ENV PORT 3000
  35. # Next.js collects completely anonymous telemetry data about general usage.
  36. # Learn more here: https://nextjs.org/telemetry
  37. # Uncomment the following line in case you want to disable telemetry.
  38. # ENV NEXT_TELEMETRY_DISABLED 1
  39. CMD ["node_modules/.bin/next", "start"]