Next.js Self-Hosting with Docker: 1.2GB image

Опубликовано: 11 Август 2026
на канале: TheCodeForge
7
0

A 1.2GB image — the multi-stage build cut it 10x. Root cause: Shipped dev deps + source in the runtime image. The fix: Multi-stage build + `output: 'standalone'`.

A production war story from the TheCodeForge Next.js series — the incident, why it happened, and the exact fix.

⏳ Timestamps:
0:00 - Cold open: 512MB container OOM at 1,000 concurrent users
0:13 - Version Compatibility: Standalone Output in Next.js ‹12
0:53 - Production Caveat: PM2 Graceful Shutdown
1:15 - Intro
1:25 - What Is Self-Hosting?
1:39 - Standalone Output
2:10 - Multi-Stage Docker Build
2:39 - Node.js Memory Limits
3:11 - PM2 Clustering
3:41 - 512MB container OOM at 1,000 concurrent users
4:04 - Missing standalone output mode
4:19 - Incident Deep Dive: The Fix
4:39 - ⚠ Gotcha: Missing standalone output in Dockerfile
4:56 - ⚠ Gotcha: Using PM2 without standalone output
5:11 - ⚠ Gotcha: Forgetting output: 'standalone' in config
5:24 - ⚠ Gotcha: Running npm install in production stage
5:36 - ⚠ Gotcha: Not setting --max-old-space-size
5:50 - ⚠ Gotcha: Serving static assets from Next.js process
6:04 - ⚠ Gotcha: Using NEXT_PUBLIC for API endpoints
6:15 - Static Asset Caching
6:47 - Environment Variables at Runtime
7:14 - Health Checks
7:40 - Logging and Observability
8:04 - Debugging Guide
8:15 - Interview Questions
8:41 - FAQ
9:03 - Key Takeaways
9:19 - Next up
9:44 - Wrap-up

👉 Full article + code: https://thecodeforge.io/javascript/ne...
⏭ Next up: OpenTelemetry, Monitoring, and Observability in Next.js 16

#nextjs #javascript