---
title: "Docker layers: 6 rules for smaller images"
slug: docker-layers-6-rules-for-smaller-images
canonical_url: https://oreoro.github.io/posts/docker-layers-6-rules-for-smaller-images/
published_at: 2026-06-04T00:00:00.000Z
updated_at: 2026-06-04T00:00:00.000Z
tags: 
  - Tools
excerpt: "A tiny checklist to cut build time and image size."
author: "Unknown Author"
---

## Navigation Context

- Canonical URL: https://oreoro.github.io/posts/docker-layers-6-rules-for-smaller-images/
- You are here: Home > Posts > Docker layers: 6 rules for smaller images

### Useful Next Links
- [Home](https://oreoro.github.io/)
- [Contact](https://oreoro.github.io/contact/)
- [Donate](https://oreoro.github.io/donate/)
- [Personal Notes](https://oreoro.github.io/collections/personal-notes/)

### 6 rules

1.  Use a small base (alpine/distroless when possible)
2.  Copy only what you need (use `.dockerignore`)
3.  Install deps before copying app source
4.  Combine commands to reduce layers
5.  Use multi-stage builds
6.  Pin versions to avoid surprise rebuilds

```
FROM node:24-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM gcr.io/distroless/nodejs24-debian12
COPY --from=build /app/dist /app
CMD ["/app/index.js"]
```