CoachnestCoachnest
Sign InGet Started
Back to course

Next.js 16: The Complete Developer Guide

…
—
Contents
1

What's New in Next.js 16

Reading14mFree
2

Installation, CLI & Your First Project

Reading12mFree
3

Project Structure & Conventions Deep Dive

Reading16m
4

Turbopack — The New Default Bundler

Video18m
5

Configuring TypeScript, ESLint & next.config.ts

Reading14m
6

Chapter 1 — Quiz

Quiz10m
7

App Router Fundamentals

Reading16m
8

Dynamic Routes, Catch-Alls & Type-Safe Params

Reading14m
9

Route Groups & Parallel Routes

Reading16m
10

Intercepting Routes & Modal Patterns

Reading12m
11

Loading, Error & Not-Found UI

Reading12m
12

Chapter 2 — Routing Quiz

Quiz12m
13

Understanding the Server/Client Boundary

Reading18m
14

Choosing When to use "use client"

Reading14m
15

Composing Server & Client Components

Reading14m
16

server-only, client-only & Code Splitting

Reading12m
17

Chapter 3 — Quiz

Quiz10m
18

Fetching Data in Server Components

Reading14m
19

The Next.js 16 Cache Model

Reading16m
20

Revalidation: revalidateTag, revalidatePath & On-Demand

Reading12m
21

Cache Components — Building Reusable Cached Functions

Reading14m
22

Search Params, Cookies & Dynamic APIs

Reading12m
23

Chapter 4 — Quiz

Quiz12m
24

Server Actions From First Principles

Reading16m
25

Forms with useActionState & Progressive Enhancement

Reading14m
26

Optimistic UI with useOptimistic

Reading12m
27

Validation with Zod + Server Actions

Reading12m
28

Chapter 5 — Quiz

Quiz10m
29

Static vs Dynamic vs Streaming

Reading14m
30

generateStaticParams & Pre-Rendering Dynamic Routes

Reading12m
31

Incremental Static Regeneration (ISR)

Reading12m
32

Partial Prerendering (PPR)

Reading16m
33

Edge Runtime vs Node.js Runtime

Reading12m
34

Rendering Strategies Deep Dive

Video22m
35

Chapter 6 — Quiz

Quiz12m
36

Tailwind CSS v4 with Next.js 16

Reading14m
37

CSS Modules, Global Styles & Scoped CSS

Reading10m
38

next/image — Smart, Fast Images

Reading14m
39

Fonts, Icons & Metadata

Reading12m
40

Chapter 7 — Quiz

Quiz10m
41

Middleware Fundamentals

Reading14m
42

Sessions, JWTs & Cookies

Reading16m
43

Protecting Server Components & Server Actions

Reading12m
44

Chapter 8 — Quiz

Quiz10m
45

Prisma with Next.js — The Production Setup

Reading14m
46

Mutations: Server Actions + Database Writes

Reading12m
47

Route Handlers & REST APIs

Reading12m
48

Chapter 9 — Quiz

Quiz10m
49

Unit & Component Testing with Vitest

Reading12m
50

End-to-End Testing with Playwright

Reading14m
51

Deploying to Vercel

Reading12m

Self-Hosting with Docker

Reading14m
53

Production Performance Checklist

Reading12m
54

Final Assessment — Next.js 16 Mastery

Quiz20m
←→navigate lessons
Chapter 10 of 10·Chapter 10 — Testing, Deployment & Production
Lesson 52 of 54Reading14 min

Self-Hosting with Docker

#Self-Hosting with Docker¶

Next.js doesn't require Vercel. Any container platform — Docker, Kubernetes, Fly.io, Railway, Render — can run a Next.js app.

next.config.ts — Standalone Output¶

ts
3 lines
1const config: NextConfig = {
2  output: "standalone",
3};

With output: "standalone", next build produces a self-contained .next/standalone folder including a minimal node_modules — perfect for Docker.

A Production Dockerfile¶

dockerfile
33 lines
1# 1. Install deps with a lockfile-only layer for cacheability
2FROM node:20-alpine AS deps
3WORKDIR /app
4COPY package.json package-lock.json* ./
5RUN npm ci
6
7# 2. Build the app
8FROM node:20-alpine AS builder
9WORKDIR /app
10COPY --from=deps /app/node_modules ./node_modules
11COPY . .
12ENV NEXT_TELEMETRY_DISABLED 1
13RUN npm run build
14
15# 3. Run the slim production image
16FROM node:20-alpine AS runner
17WORKDIR /app
18ENV NODE_ENV production
19ENV NEXT_TELEMETRY_DISABLED 1
20
21RUN addgroup --system --gid 1001 nodejs
22RUN adduser --system --uid 1001 nextjs
23
24COPY --from=builder /app/public ./public
25COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
26COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
27
28USER nextjs
29EXPOSE 3000
30ENV PORT 3000
31ENV HOSTNAME "0.0.0.0"
32
33CMD ["node", "server.js"]

.dockerignore¶

node_modules .next .git .env.local .env.development README.md tests *.log

Build & Run¶

bash
5 lines
1docker build -t my-app .
2docker run -p 3000:3000 \
3  -e DATABASE_URL=postgres://... \
4  -e SESSION_SECRET=... \
5  my-app

docker-compose for Local Stack¶

yaml
18 lines
1services:
2  web:
3    build: .
4    ports: ["3000:3000"]
5    environment:
6      DATABASE_URL: postgresql://postgres:secret@db:5432/myapp
7      SESSION_SECRET: dev-secret-not-for-prod
8    depends_on: [db]
9
10  db:
11    image: postgres:16-alpine
12    environment:
13      POSTGRES_PASSWORD: secret
14      POSTGRES_DB: myapp
15    volumes: ["db:/var/lib/postgresql/data"]
16
17volumes:
18  db:

docker compose up boots the whole stack.

ISR & Cache on Self-Hosted¶

The default cache uses the local filesystem — fine for single-replica, problematic for horizontal scaling. For multi-instance:

ts
5 lines
1// next.config.ts
2const config: NextConfig = {
3  cacheHandler: require.resolve("./cache-handler.js"),
4  cacheMaxMemorySize: 0,
5};

Implement a Redis-backed cache handler — examples in the Next.js docs.

Image Optimization¶

The default image optimizer requires sharp. node:20-alpine ships musl libc — install vips-dev build tools if you hit issues:

dockerfile
2 lines
1FROM node:20-alpine
2RUN apk add --no-cache vips-dev

Or set images: { unoptimized: true } and let your CDN (Cloudflare, CloudFront, Imgix) handle resizing.

Reverse Proxy (Nginx)¶

nginx
12 lines
1server {
2  listen 80;
3  server_name yourapp.com;
4
5  location / {
6    proxy_pass http://localhost:3000;
7    proxy_set_header Host \$host;
8    proxy_set_header X-Real-IP \$remote_addr;
9    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
10    proxy_set_header X-Forwarded-Proto \$scheme;
11  }
12}

Add Let's Encrypt with Certbot, you're production-ready.

Pros & Cons vs Vercel¶

VercelSelf-Hosted
Time to first deploy5 min1–2 hours
Edge networkWorldwideWherever you deploy
ISR / cacheBuilt-inBring your own
Image optimizationFreesharp install needed
Cost at scale$$$$ (raw compute)
Lock-inSomeNone

For most startups, Vercel until ~$1k/month in bills, then evaluate. For enterprises with regulated workloads, self-host from day one.

Previous

Deploying to Vercel

Next

Production Performance Checklist

Use ← → arrow keys to navigate between lessons