DevOps
Containerizing a Next.js App with Docker
SSite Admin
22 tháng 06, 2026 1 phút đọc 283 lượt xemShipping 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.
S
Site Admin
Engineer and writer. Building things with TypeScript and distributed systems.
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.