Careeroza
Standalone Output and Docker
output: 'standalone'
This option makes next build create .next/standalone: a minimal server.js plus only the node_modules files that are actually used. Images shrink from ~1 GB to ~150 MB.
next.config.ts
next.config.ts
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
output: 'standalone',
};
export default nextConfig;Multi-stage Dockerfile
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
FROM node:22-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npx prisma generate && npm run build
FROM node:22-alpine AS run
WORKDIR /app
ENV NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0
RUN addgroup -S app && adduser -S app -G app
COPY --from=build /app/public ./public
COPY --from=build --chown=app:app /app/.next/standalone ./
COPY --from=build --chown=app:app /app/.next/static ./.next/static
USER app
EXPOSE 3000
CMD ["node", "server.js"]Note: The standalone folder does not include public/ and .next/static; copy them yourself (or serve them from a CDN).
Build and Run
Example
docker build -t shopease-web:1.0 .
docker run -p 3000:3000 --env-file .env.production shopease-web:1.0Example output
=> [run 6/6] COPY --from=build /app/.next/static ./.next/static => exporting to image => => naming to docker.io/library/shopease-web:1.0 ▲ Next.js 15.5.4 - Local: http://localhost:3000 ✓ Ready in 95ms
Tip: See the Docker material for docker-compose with PostgreSQL.