dockerfile 1.7 KB

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