From 7b3724c1e716ababe4c76e7fa59bc2f3ddf3da05 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 16 Sep 2025 09:14:13 +0200 Subject: [PATCH] Add Dockerfile for Next.js SPA deployment --- nextjs/spa/Dockerfile | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 nextjs/spa/Dockerfile diff --git a/nextjs/spa/Dockerfile b/nextjs/spa/Dockerfile new file mode 100644 index 0000000..02dc0ab --- /dev/null +++ b/nextjs/spa/Dockerfile @@ -0,0 +1,53 @@ +FROM node:22-alpine AS base + +# ======================================== +# Dependencies Stage +# ======================================== +FROM base AS deps +RUN apk add --no-cache libc6-compat python3 make g++ git +WORKDIR /app + +COPY package.json yarn.lock ./ + +RUN yarn install --frozen-lockfile --network-timeout 600000 || \ + (yarn cache clean && yarn install --frozen-lockfile --network-timeout 600000) + +# ======================================== +# Builder Stage +# ======================================== +FROM base AS builder +WORKDIR /app + +COPY --from=deps /app/node_modules ./node_modules + +COPY . . + +ARG COOLIFY_URL +ENV NEXT_PUBLIC_BASE_URL=${COOLIFY_URL} + +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_PRIVATE_STANDALONE=true + +RUN yarn build + +# ======================================== +# Runner Stage +# ======================================== +FROM base AS runner +WORKDIR /app + +RUN apk add --no-cache libc6-compat curl + +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 + +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 + +CMD ["node", "server.js"]