Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # syntax=docker.io/docker/dockerfile:1
  2. FROM node:18-alpine AS base
  3. # Install dependencies only when needed
  4. FROM base AS deps
  5. # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
  6. RUN apk add --no-cache libc6-compat
  7. WORKDIR /app
  8. # Install dependencies based on the preferred package manager
  9. COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
  10. RUN \
  11. if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  12. elif [ -f package-lock.json ]; then npm ci; \
  13. elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
  14. else echo "Lockfile not found." && exit 1; \
  15. fi
  16. # Rebuild the source code only when needed
  17. FROM base AS builder
  18. WORKDIR /app
  19. COPY --from=deps /app/node_modules ./node_modules
  20. COPY . .
  21. RUN npx prisma generate
  22. # Next.js collects completely anonymous telemetry data about general usage.
  23. # Learn more here: https://nextjs.org/telemetry
  24. # Uncomment the following line in case you want to disable telemetry during the build.
  25. # ENV NEXT_TELEMETRY_DISABLED=1
  26. RUN \
  27. if [ -f yarn.lock ]; then yarn run build; \
  28. elif [ -f package-lock.json ]; then npm run build; \
  29. elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
  30. else echo "Lockfile not found." && exit 1; \
  31. fi
  32. # Production image, copy all the files and run next
  33. FROM base AS runner
  34. WORKDIR /app
  35. ENV NODE_ENV=production
  36. # Uncomment the following line in case you want to disable telemetry during runtime.
  37. # ENV NEXT_TELEMETRY_DISABLED=1
  38. RUN addgroup --system --gid 1001 nodejs
  39. RUN adduser --system --uid 1001 nextjs
  40. COPY --from=builder /app/public ./public
  41. # Automatically leverage output traces to reduce image size
  42. # https://nextjs.org/docs/advanced-features/output-file-tracing
  43. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
  44. COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
  45. USER nextjs
  46. EXPOSE 3000
  47. ENV PORT=3000
  48. # server.js is created by next build from the standalone output
  49. # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
  50. ENV HOSTNAME="0.0.0.0"
  51. CMD ["node", "server.js"]