docker-best-practices
Installation
SKILL.md
Docker best practices
Use when authoring **Dockerfile**s, .dockerignore, image CI, or container runtime config for services in this monorepo.
Images and build stages
- Prefer multi-stage builds: compile or install in a builder stage, copy only artifacts into a minimal runtime image.
- Use small bases for runtime where possible (
*-slim,distroless, or static binaries). Keep runtimes pin-aligned with local dev (Node and Rust versions should matchengines,rust-toolchain.toml, or CI). - Order Dockerfile instructions from least to most frequently changing so layer cache helps (dependency manifests before source, shared layers before app-specific).
Build context
- Keep
.dockerignoreaggressive: exclude VCS metadata, CI config, unrelated apps, build outputs, and secrets. A smaller context means faster builds and fewer accidental leaks into layers. - Avoid
COPY . .without a strong ignore file; prefer explicitCOPYlists when the repo layout is stable.
Reproducibility
- Use lockfiles (
pnpm-lock.yaml,Cargo.lock) and flags likepnpm install --frozen-lockfileandcargo build --lockedin CI and images. - Pin base image digests in production pipelines when you need byte-stable rebuilds (optional for dev images).