Standalone Output
Set output: 'standalone' to produce a minimal, self-contained build ideal for Docker.
Syntax
output: 'standalone'By default a Next.js production build expects node_modules to be present. Setting output: 'standalone' makes the build copy only the files it actually needs into a .next/standalone folder, producing a small, portable server you can run with plain Node β perfect for Docker images.
Example
// next.config.ts
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
output: 'standalone',
};
export default nextConfig;
// After `npm run build`, run the server with:
// node .next/standalone/server.jsWhen to use it
- A team packages a Next.js app in a Docker image using standalone output so the image contains only necessary files, cutting its size dramatically.
- A Kubernetes deployment uses the standalone server.js output to run the app with zero npm install on startup.
- A self-hosted VM deployment copies the standalone folder to the server instead of the full node_modules tree.
More examples
Enable standalone output
Setting output: 'standalone' makes next build produce a .next/standalone directory with a minimal Node server.
// next.config.ts
export default {
output: 'standalone',
};Dockerfile for standalone build
The multi-stage Dockerfile copies only the standalone output, producing a production image without source code or dev dependencies.
FROM node:22-alpine AS builder
WORKDIR /app
COPY . .
RUN npm ci && npm run build
FROM node:22-alpine AS runner
WORKDIR /app
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"]Run standalone server manually
The standalone server.js runs the full Next.js app with no additional npm install, ideal for minimal deployment targets.
# After build:
npm run build
# Copy static files into standalone output
cp -r .next/static .next/standalone/.next/static
cp -r public .next/standalone/public
# Start the server
node .next/standalone/server.js
Discussion