Update Dockerfile

This commit is contained in:
Greg 2025-08-09 21:37:23 +00:00
parent d7eb8b23f7
commit 78734c15d1

View File

@ -1,8 +1,9 @@
# ---- 1) Install deps (cached) ---------------------------------------------- # ---- 1) Install deps --------------------------------------------------------
FROM node:20-alpine AS deps FROM node:20-alpine AS deps
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
RUN npm ci # Works even if there is no package-lock.json
RUN npm install
# ---- 2) Build the Next.js app ---------------------------------------------- # ---- 2) Build the Next.js app ----------------------------------------------
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
@ -12,27 +13,26 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
RUN npm run build RUN npm run build
# ---- 3) Runtime: copy standalone output, run as non-root ------------------- # ---- 3) Runtime -------------------------------------------------------------
FROM node:20-alpine AS runner FROM node:20-alpine AS runner
WORKDIR /app WORKDIR /app
# Environment
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000 ENV PORT=3000
# Non-root user # run as non-root
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
# Copy only what's needed to run the server # Copy the built app and runtime deps
# - .next/standalone includes server.js and minimal node_modules COPY --from=builder /app/.next ./.next
# - .next/static and public are needed for assets
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/node_modules ./node_modules
# Trim dev deps from node_modules (optional but nice)
RUN npm prune --omit=dev
# Expose Next.js port
EXPOSE 3000 EXPOSE 3000
USER 1001 USER 1001
CMD ["node", "server.js"] CMD ["npm", "start"]