From 455560f74c67451664449210d500bcd8002b1c08 Mon Sep 17 00:00:00 2001 From: thewebmasterpro Date: Wed, 4 Mar 2026 23:52:43 +0100 Subject: [PATCH] Add Docker deployment config - Add multi-stage Dockerfile for Next.js standalone - Add .dockerignore - Enable standalone output in next.config.ts Co-Authored-By: Claude Opus 4.6 --- .dockerignore | 7 +++++++ Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ next.config.ts | 3 +++ 3 files changed, 46 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4be2b86 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.next +.git +.gitignore +*.md +.env*.local +.claude diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eabd6d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM node:20-alpine AS base + +# --- Dependencies --- +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm ci + +# --- Build --- +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NEXT_TELEMETRY_DISABLED=1 +RUN npm run build + +# --- Production --- +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 +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs +EXPOSE 3000 +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index d0af103..8537901 100644 --- a/next.config.ts +++ b/next.config.ts @@ -53,6 +53,9 @@ const securityHeaders = [ ]; const nextConfig: NextConfig = { + // Standalone output for Docker deployment + output: "standalone", + // Security headers async headers() { return [