Skip to content
ProductionChapter 34 / 34Intermediate5 min read

Deployment

Next.js deployment on Vercel, Docker and your own server - output standalone, next start and a production checklist, explained step by step.

On this page

1. What is deployment?

Next.js has four main paths:

OptionFeature support
Vercel (verified adapter)All features, zero config
Node.js server (next start)All features
Docker containerAll features
Static export (output: "export")Limited, no server features

2. Why does it matter?

next dev is only for development: it is slow, unoptimized and comes with debugging tools. Production needs an optimized build, caching and the right environment variables.

next devProduction deployment
Compiles on demand for every requestAn already optimized build
Unminified code and dev warningsMinified, code-split bundles
Runs on your local machineRuns 24/7 on a server or platform
Local env filesThe platform's secure environment variables
One user, youThousands of users, scaling and caching

3. Where is it used?

SituationBetter choice
Personal project, startup, fast launchVercel
Your own VPS (Hostinger, DigitalOcean)next build + next start, with PM2 or systemd
Kubernetes, Cloud Run, Fly.ioDocker + output: "standalone"
A static marketing site onlyoutput: "export", on any static host

4. How does it work?

From code to production
git push
next build (Turbopack) creates the optimized output
Static pages, server code and assets are separated
The platform or server runs next start
Users get the production app

On Vercel all of this happens automatically: connect your GitHub repo, and every push creates a preview deployment, while the main branch creates a production deployment.

5. Code example

Self-hosting: Node.js server

json
{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  }
}
bash
npm ci
npm run build
PORT=3000 npm run start

Standalone output for Docker

ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  output: "standalone",
};

export default nextConfig;
bash
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]

The code above is the Dockerfile. Build and run:

bash
docker build -t znpedia .
docker run -p 3000:3000 --env-file .env.production znpedia

Deploying with the Vercel CLI

bash
npm i -g vercel
vercel
vercel --prod

How does the code work?

ItemMeaning
next buildThe production build in the .next folder
next startThe production server, default port 3000
output: "standalone"Only the needed files and server.js in .next/standalone
Copying .next/static and publicStandalone does not copy these itself, so the Dockerfile has to
Multi-stage buildThe builder's heavy dependencies do not end up in the final image
--env-fileSecrets are not baked into the image, they arrive at runtime
vercel --prodA production deployment, without the flag it is a preview

6. Common mistakes

Mistake: Running next dev on a production server

Why? Dev mode is slow, compiles on every request and turns off production optimizations.

Better: On the server, always run next build and then next start.

Mistake: Not copying static and public in a standalone output

Why? The page opens, but the CSS, JS chunks and images return 404.

Better: Copy the .next/static and public folders next to standalone in the Dockerfile, or serve them from a CDN.

Mistake: Trying to change NEXT_PUBLIC variables at runtime

Why? NEXT_PUBLIC_ values are written into the client bundle at build time, so changing them later has no effect.

Better: Set public values before the build, and read values needed at runtime from process.env on the server.

Mistake: Copying secrets into the Docker image

Why? As soon as the image is shared or pushed, the secrets from .env leak too.

Better: Keep secrets in .dockerignore and provide them at runtime through env vars or platform secrets.

Interview tip

"What does output: "standalone" do?" During the build, Next.js traces which files and node_modules packages are needed at runtime, and puts only those in .next/standalone along with a server.js. This makes the Docker image much smaller.

7. What to learn before and after

Final quick revision

PointDetail
EasiestVercel, connect Git and deploy
Your own servernext build then next start
Dockeroutput: "standalone" and node server.js
Copy with standalone.next/static and public
Static siteoutput: "export", limited features