dockerfile 1.8 KB

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