Overview
This portfolio includes a multi-stage Dockerfile optimized for production builds using Next.js standalone output mode. Docker provides consistent deployment environments and efficient resource usage.Production Deployment
Build the Docker Image
The Dockerfile uses a three-stage build process for optimal image size:Build Stages:
- deps: Installs dependencies using frozen lockfile (supports npm, pnpm, or yarn)
- builder: Creates Next.js standalone build with
output: "standalone" - runner: Lean runtime image containing only production assets
Dockerfile Configuration
The production Dockerfile implements Next.js best practices:The
output: "standalone" configuration in next.config.mjs is required for Docker builds. This creates a minimal production server with automatic code tracing.Development Setup with Hot Reload
For local development with live code updates, use Docker Compose:Access the Application
Open
http://localhost:3000 in your browser. Changes to source files will automatically reload.Development Docker Compose Configuration
Docker Ignore Configuration
The.dockerignore file excludes unnecessary files from the build context:
Environment Variables
Build Optimization
Multi-stage Benefits:- Smaller image size: Only production dependencies and built assets in final image
- Security: No source code or build tools in runtime image
- Performance: Node.js standalone output includes only required dependencies
- Full build with dev dependencies: ~1.2GB
- Standalone multi-stage build: ~150MB
Deployment to Cloud Platforms
Troubleshooting
Build fails at dependencies stage:- Ensure your lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock) is committed
- Check for platform-specific dependencies requiring
libc6-compat
- Verify
output: "standalone"is set innext.config.mjs - Check that
server.jsexists in.next/standalone/after build
- Change the host port mapping:
docker run -p 8080:3000 luan/portfolio