Dockerfile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Install dependencies only when needed
  2. FROM node:16-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. # If using npm with a `package-lock.json` comment out above and use below instead
  9. COPY package.json package-lock.json ./
  10. COPY node_modules ./node_modules
  11. COPY .next ./.next
  12. # RUN npm ci
  13. # Rebuild the source code only when needed
  14. FROM node:16-alpine AS builder
  15. WORKDIR /app
  16. COPY --from=deps /app/node_modules ./node_modules
  17. COPY . .
  18. # Next.js collects completely anonymous telemetry data about general usage.
  19. # Learn more here: https://nextjs.org/telemetry
  20. # Uncomment the following line in case you want to disable telemetry during the build.
  21. # ENV NEXT_TELEMETRY_DISABLED 1
  22. # RUN npm run build
  23. # If using npm comment out above and use below instead
  24. # RUN npm run build
  25. # Production image, copy all the files and run next
  26. FROM node:16-alpine AS runner
  27. WORKDIR /app
  28. ENV NODE_ENV production
  29. # Uncomment the following line in case you want to disable telemetry during runtime.
  30. # ENV NEXT_TELEMETRY_DISABLED 1
  31. RUN addgroup --system --gid 1001 nodejs
  32. RUN adduser --system --uid 1001 nextjs
  33. # You only need to copy next.config.js if you are NOT using the default configuration
  34. COPY --from=builder /app/next.config.js ./
  35. COPY --from=builder /app/public ./public
  36. COPY --from=builder /app/package.json ./package.json
  37. # Automatically leverage output traces to reduce image size
  38. # https://nextjs.org/docs/advanced-features/output-file-tracing
  39. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
  40. COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
  41. USER nextjs
  42. EXPOSE 3000
  43. ENV PORT 3000
  44. CMD ["node", "server.js"]