Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Docker Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/adityaaatiwari-docker-best-practices-anvil)
---
name: docker-best-practices
description: Build small, secure, fast and reproducible container images with multi-stage builds, cache mounts and non-root runtimes
---
<!-- Generated by `anvil plugin build` from catalog/. Edit the catalog, not this file. -->
# Docker best practices
Use when writing or slimming down a `Dockerfile` or `.dockerignore`.
## Layering and build speed
- Start with a thorough `.dockerignore` (`.git`, `node_modules`, test fixtures, `.env*`, build outputs) to shrink the build context.
- Order instructions from least to most frequently changing: base image -> OS packages -> dependency manifests -> lockfile install -> application source -> build.
- Use BuildKit cache mounts (`--mount=type=cache,...`) for package manager caches instead of baking caches into layers.
## Runtime image hygiene
- Pin base images by tag and digest; prefer `distroless`, `slim` or `alpine` runtime stages.
- Use multi-stage builds so compilers, headers and devDependencies never ship in the final stage.
- Create and switch to an unprivileged `USER` with a numeric UID/GID; use a read-only filesystem where possible.
- Never bake secrets into layers; use `--mount=type=secret` at build time or runtime environment.
- Use JSON array (`exec`) form for `ENTRYPOINT` and `CMD` so `SIGTERM` reaches your process directly.
## Verify
Run `docker build`, inspect layer sizes with `docker history`, check the runtime user with `docker run --rm --entrypoint id <image>`, and scan for CVEs.