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
alpinevariants — typically 5-10 MB vs 100+ MB for full imagesdistrolessimages — contain only your app and runtime dependenciesscratch— 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.