# Multi-stage Dockerfile for Diesel Depot. # Designed for Coolify (which runs any standard Dockerfile on a Node host). # Build context: the project root. # # Build: docker build -t diesel-depot . # Run: docker run --rm -p 4002:3000 -e NEXT_PUBLIC_POCKETBASE_URL=... diesel-depot # # In Coolify, point the service at this Dockerfile. Coolify will set PORT # (default 3000) automatically and inject any env vars you add in the UI. # ─── Stage 1: install deps in a clean layer ───────────────────────────────── FROM node:20-alpine AS deps RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json package-lock.json ./ # `npm ci` is reproducible (uses lockfile); falls back to `npm install` if no lockfile. RUN npm ci --no-audit --no-fund || npm install --no-audit --no-fund # ─── Stage 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 . . # Build with the standalone output (set by next.config.mjs when NEXT_EXPORT is not "true"). RUN npm run build # ─── Stage 3: minimal runtime image ───────────────────────────────────────── FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 # Coolify / Docker injects $PORT. Default to 3000 for local docker run. ENV PORT=3000 ENV HOSTNAME=0.0.0.0 # Run as the unprivileged `node` user (built into the node:alpine image). RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 --ingroup nodejs nextjs # Copy the standalone output. Standalone already includes only the runtime # node_modules it needs, so this is the only thing we have to copy. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ # The .next/static and public folders are not part of standalone — copy them # over so the static assets and PWA manifest/icons work. COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/public ./public USER nextjs EXPOSE 3000 # Coolify sends SIGTERM on stop; `node server.js` forwards it cleanly. CMD ["node", "server.js"]