Skip to content
Aditya Bhalsod
← DevOps
DevOpsBeginner

A Deployment Checklist for Next.js, From Vercel to Your Own Docker Host

The settings I check on every Next.js project so the same codebase deploys cleanly to Vercel previews and to a self-hosted Docker container using standalone output.

  • #nextjs
  • #docker
  • #vercel
  • #ci-cd
Contents
  1. 1. Use standalone output
  2. 2. Be strict about environment variables
  3. 3. A small multi-stage Dockerfile
  4. Don't forget static assets
  5. 4. Add a health check
  6. 5. Preview every pull request

Many of my client projects start on Vercel for its preview deployments and later need to run on the client's own infrastructure too. Next.js handles both well if you set a few things up from the start. This is the checklist I run through.

1. Use standalone output

In next.config.mjs:

JavaScript
const nextConfig = {
  output: 'standalone',
};
export default nextConfig;

next build then writes .next/standalone, a self-contained Node server with only the dependencies it actually uses. Vercel ignores this setting and uses its own build output, so you lose nothing by enabling it.

2. Be strict about environment variables

Anything prefixed NEXT_PUBLIC_ is inlined into the browser bundle at build time. That has two consequences:

  • Secrets must never use the prefix.
  • Changing a public variable requires a rebuild, not just a restart.

3. A small multi-stage Dockerfile

Dockerfile
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci

FROM node:20-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

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

The final stage contains no source code and no dev dependencies.

Don't forget static assets

The standalone folder does not include public/ or .next/static. Copy both, or images and CSS will 404 in production while working fine locally.

4. Add a health check

A tiny route handler at /api/health that returns 200 lets your load balancer, Docker or uptime monitor know the app is actually serving, not just that the container is running.

5. Preview every pull request

Connect the repository to Vercel and every pull request gets its own URL. Reviewers click through real pages instead of reading diffs, and missing environment variables show up before the merge, not after.

CheckVercelDocker
Standalone outputignored, harmlessrequired
public/ and .next/staticautomaticcopy manually
Env varsproject settingsruntime + build args
Previewsper PRset up yourself

With these in place, the same repository deploys to either target without special cases in the code.

Found this useful? Share it with your team.

Keep reading

More from DevOps and beyond