Keep/keep-notes/Dockerfile

61 lines
1.6 KiB
Docker

# Multi-stage build for Next.js 16 with Webpack (not Turbopack)
# Turbopack has issues with Tailwind CSS 4 in Docker containers
FROM node:22-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Install OpenSSL and compatibility libraries for Prisma
RUN apk add --no-cache libc6-compat libssl1.1
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json package-lock.json* ./
RUN npm install --legacy-peer-deps
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma Client before build
RUN npx prisma generate
# Build Next.js with Webpack (not Turbopack) to avoid Tailwind CSS issues
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy Prisma for runtime
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# server.js is created by next build from the standalone output
CMD ["node", "server.js"]