# Writing Efficient Dockerfiles — Docker Fundamentals: Images, Containers and Compose

Source: https://www.skillbyai.com/en/docker/docker-efficient-dockerfiles

> Order Dockerfile instructions for layer caching and choose small base images for fast builds.

## Order matters for caching

Put instructions that **change rarely** (installing dependencies) before instructions that **change often** (copying source code) so cache hits happen more often.

## Prefer slim/alpine bases

`node:20-alpine` can be a tenth the size of `node:20`. Smaller images pull faster, deploy faster, and have less surface for vulnerabilities.
