Multi-Stage Dockerfile
Multi-stage builds significantly reduce image size. Stage 1: install dependencies. Stage 2: build the app. Stage 3: a lean production image containing only the necessary output.
Docker Compose for Development
Use docker-compose.yml to set up a local dev environment with Next.js, PostgreSQL, and Redis. Hot reload still works thanks to volume mounts.
Environment Variables
Distinguish between build-time vars (ARG) and runtime vars (ENV). NEXT_PUBLIC_* vars are needed at build time; server-side vars are only needed at runtime.
Health Checks
Add a HEALTHCHECK instruction in your Dockerfile so container orchestrators can detect whether the app is healthy. Wire it to a /api/health endpoint.
Deploy Options
Vercel is the simplest choice for Next.js. But if you need more control: Docker on Railway, Fly.io, or self-hosted with Coolify. I recommend Vercel for most projects.