Optimize Dockerfile for smaller image size using Next.js standalone
All checks were successful
Build Frontend / build (push) Successful in 1m4s
All checks were successful
Build Frontend / build (push) Successful in 1m4s
This commit is contained in:
16
Dockerfile
16
Dockerfile
@@ -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
|
||||
|
||||
# ---- 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
|
||||
|
||||
# Set working directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm in production stage
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
# Copy the standalone build from builder
|
||||
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 --from=builder /app/package.json /app/pnpm-lock.yaml ./
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
# Copy public files
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# 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
|
||||
|
||||
# Start Next.js server
|
||||
CMD ["pnpm", "run", "start"]
|
||||
CMD ["node", "server.js"]
|
||||
Reference in New Issue
Block a user