Docs / Performance Optimization / How to Reduce Docker Image Sizes for Faster Deployments

How to Reduce Docker Image Sizes for Faster Deployments

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 29 views · 2 min read

How to Reduce Docker Image Sizes for Faster Deployments

Smaller Docker images mean faster pulls, less storage, and quicker deployments on your Breeze server. Here are proven strategies to minimize image sizes.

Use Multi-Stage Builds

Separate build dependencies from the runtime image:

FROM node:20 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]

Choose Minimal Base Images

  • alpine variants — typically 5-10 MB vs 100+ MB for full images
  • distroless images — contain only your app and runtime dependencies
  • scratch — empty base for statically compiled binaries

Optimize Layer Caching

# Bad: COPY everything first (busts cache on any change)
COPY . .
RUN npm ci

# Good: Copy dependency files first
COPY package*.json ./
RUN npm ci
COPY . .

Create a Proper .dockerignore

node_modules
.git
*.md
.env*
tests/
coverage/
.github/

Minimize Layers and Clean Up

RUN apt-get update && \
    apt-get install -y --no-install-recommends build-essential && \
    make build && \
    apt-get purge -y build-essential && \
    apt-get autoremove -y && \
    rm -rf /var/lib/apt/lists/*

Analyzing Image Sizes

# Check image size
docker images myapp

# Analyze layers with dive
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive myapp:latest

Regularly audit your images to keep Breeze deployments fast and efficient.

Was this article helpful?