Skip to main content
Dockerizing for Production Deployment

Dockerizing for Production Deployment

Andrius LukminasAndrius LukminasDecember 30, 20255 min read194 views

Why Docker?

Consistent environments across development, staging, and production. No more "works on my machine" issues.

Our Dockerfile

We use a multi-stage build for optimal image size:

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

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

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
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"]

Key Optimizations

  • Alpine base - Minimal image size
  • Standalone output - No node_modules in final image
  • Layer caching - Dependencies layer cached separately
  • Lowercase names - OCI spec requires lowercase image names

GitHub Actions Integration

Our CI/CD pipeline builds and pushes images on every commit to main, then deploys to our server via SSH.

Related Articles

Comments

0/5000 characters

Comments from guests require moderation.