Optimize Dockerfile for smaller image size using Next.js standalone
All checks were successful
Build Frontend / build (push) Successful in 1m4s

This commit is contained in:
g
2026-01-11 12:46:39 +00:00
parent 397177fe36
commit 506b4b2f04

View File

@@ -39,21 +39,19 @@ RUN echo "invalidate cache" && echo $(git rev-parse --short HEAD 2>/dev/null ||
NODE_OPTIONS='--max_old_space_size=2048' NEXT_TELEMETRY_DISABLED=1 pnpm run build NODE_OPTIONS='--max_old_space_size=2048' NEXT_TELEMETRY_DISABLED=1 pnpm run build
# ---- Production Stage ---- # ---- Production Stage ----
# Use Node 20 for production as well to match builder # Use a smaller base image for production
FROM node:20-alpine AS runner FROM node:20-alpine AS runner
# Set working directory inside the container # Set working directory inside the container
WORKDIR /app WORKDIR /app
# Install pnpm in production stage # Copy the standalone build from builder
RUN corepack enable && corepack prepare pnpm@latest --activate COPY --from=builder /app/.next/standalone ./
RUN mkdir -p /app/public # Copy static files
COPY --from=builder /app/.next/static ./.next/static
# Copy only necessary files from builder # Copy public files
COPY --from=builder /app/package.json /app/pnpm-lock.yaml ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
# Copy commit hash file from builder # Copy commit hash file from builder
@@ -71,4 +69,4 @@ ENV API_HOSTNAME=internal-api.inboxi.ng
# The file is available at /app/git_commit_sha if needed # The file is available at /app/git_commit_sha if needed
# Start Next.js server # Start Next.js server
CMD ["pnpm", "run", "start"] CMD ["node", "server.js"]