Dockerfile.prod 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. WORKDIR /app
  6. COPY package.json yarn.lock ./
  7. RUN yarn install --frozen-lockfile
  8. # Rebuild the source code only when needed
  9. FROM node:alpine AS builder
  10. WORKDIR /app
  11. COPY . .
  12. COPY --from=deps /app/node_modules ./node_modules
  13. RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
  14. # Production image, copy all the files and run next
  15. FROM node:alpine AS runner
  16. WORKDIR /app
  17. ENV NODE_ENV production
  18. RUN addgroup -g 1001 -S nodejs
  19. RUN adduser -S nextjs -u 1001
  20. # You only need to copy next.config.js if you are NOT using the default configuration
  21. # COPY --from=builder /app/next.config.js ./
  22. COPY --from=builder /app/public ./public
  23. COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
  24. COPY --from=builder /app/node_modules ./node_modules
  25. COPY --from=builder /app/package.json ./package.json
  26. USER nextjs
  27. EXPOSE 3000
  28. ENV PORT 3000
  29. # Next.js collects completely anonymous telemetry data about general usage.
  30. # Learn more here: https://nextjs.org/telemetry
  31. # Uncomment the following line in case you want to disable telemetry.
  32. # ENV NEXT_TELEMETRY_DISABLED 1
  33. CMD ["node_modules/.bin/next", "start"]