DevOps

Containerizing a Next.js App with Docker

MMọt Dev
23 tháng 06, 2026 1 phút đọc 3034 lượt xem
Containerizing a Next.js App with Docker

Shipping Next.js in a container gives you reproducible deploys anywhere. Multi-stage builds keep the final image small.

Multi-Stage 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 runner
WORKDIR /app
COPY --from=build /app/.next/standalone ./
CMD ["node", "server.js"]

Standalone Output

Set output: 'standalone' in next.config to bundle only the files needed at runtime.

M

Mọt Dev

Backend Engineer — Java, Spring Boot, Apache Kafka, Oracle SQL & System Design.

Bình luận (0)

Bạn cần đăng nhập bằng Google để bình luận.

Hãy là người bình luận đầu tiên.