Update Dockerfile for Next.js 15 migration with production-optimized build: - Multi-stage build separating compilation from runtime - Next.js standalone output mode (~150-200MB final image) - Non-root user (nextjs:1000) for security hardening - Health check endpoint for orchestration monitoring - Node.js 20 Alpine runtime for minimal footprint Add .dockerignore to exclude development files from build context, reducing build time and image size. Update README with comprehensive Docker deployment documentation including environment variable configuration and image features. OpenSpec: Implements fix-dockerfile-nextjs proposal (26/30 tasks completed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
1.1 KiB
Docker
48 lines
1.1 KiB
Docker
# Build stage
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json package-lock.json ./
|
|
|
|
# Install dependencies (including dev dependencies for build)
|
|
RUN npm ci
|
|
|
|
# Copy source code and configuration
|
|
COPY . .
|
|
|
|
# Build Next.js application with standalone output
|
|
RUN npm run build
|
|
|
|
# Runtime stage
|
|
FROM node:20-alpine
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1000 nextjs && \
|
|
adduser -D -u 1000 -G nextjs nextjs
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy standalone output from builder stage
|
|
COPY --from=builder --chown=nextjs:nextjs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nextjs /app/.next/static ./.next/static
|
|
COPY --from=builder --chown=nextjs:nextjs /app/public ./public
|
|
|
|
# Set environment for production
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000/', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
|
|
|
# Run as non-root user
|
|
USER nextjs
|
|
|
|
# Start the application
|
|
CMD ["node", "server.js"]
|