Careeroza
Small & Fast Images
Choosing a Base Image
| Base | Size | Notes |
|---|---|---|
python:3.12 | ~1 GB | full Debian with build tools |
python:3.12-slim | ~125 MB | good default |
python:3.12-alpine | ~50 MB | musl libc: some packages must compile from source |
gcr.io/distroless/... | tiny | no shell or package manager; great for production |
Checklist
- Order instructions from least to most frequently changing (dependencies before code).
- Combine related
RUNsteps and clean caches in the same layer:apt-get install ... && rm -rf /var/lib/apt/lists/*. - Use
pip install --no-cache-dir/npm ci --omit=dev. - Add a
.dockerignore. - Use multi-stage builds so build tools never reach the final image.
- Use BuildKit cache mounts for package managers:
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt.