diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d846c5d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# ---- 1) Install deps (cached) ---------------------------------------------- +FROM node:20-alpine AS deps +WORKDIR /app +COPY package*.json ./ +RUN npm ci + +# ---- 2) Build the Next.js app ---------------------------------------------- +FROM node:20-alpine AS builder +WORKDIR /app +ENV NEXT_TELEMETRY_DISABLED=1 +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN npm run build + +# ---- 3) Runtime: copy standalone output, run as non-root ------------------- +FROM node:20-alpine AS runner +WORKDIR /app + +# Environment +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3000 + +# Non-root user +RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 + +# Copy only what's needed to run the server +# - .next/standalone includes server.js and minimal node_modules +# - .next/static and public are needed for assets +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +# Expose Next.js port +EXPOSE 3000 + +USER 1001 +CMD ["node", "server.js"]