dockerfile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. RUN apk add curl git pkgconfig && curl https://glide.sh/get | sh
  7. WORKDIR /app
  8. # COPY package.json yarn.lock ./
  9. # RUN yarn install --frozen-lockfile
  10. # If using npm with a `package-lock.json` comment out above and use below instead
  11. COPY package.json package-lock.json ./
  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 yarn build
  23. # Production image, copy all the files and run next
  24. FROM node:16-alpine AS runner
  25. WORKDIR /app
  26. ENV NODE_ENV production
  27. # Uncomment the following line in case you want to disable telemetry during runtime.
  28. ENV NEXT_TELEMETRY_DISABLED 1
  29. RUN addgroup --system --gid 1001 nodejs
  30. RUN adduser --system --uid 1001 nextjs
  31. # You only need to copy next.config.js if you are NOT using the default configuration
  32. COPY --from=builder /app/next.config.js ./
  33. COPY --from=builder /app/public ./public
  34. COPY --from=builder /app/package.json ./package.json
  35. # Automatically leverage output traces to reduce image size
  36. # https://nextjs.org/docs/advanced-features/output-file-tracing
  37. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
  38. COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
  39. USER nextjs
  40. EXPOSE 3000
  41. ENV PORT 3000
  42. CMD ["node", "server.js"]