Skip to content
Back to skills

Docker Best Practices

ASecurity

Build small, secure, fast and reproducible container images with multi-stage builds, cache mounts and non-root runtimes

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
developmentnodedockergit

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add AdityaaaTiwari/ANVIL --skill docker-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docker Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docker Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/adityaaatiwari-docker-best-practices-anvil/badge)](https://www.skillsdirectory.com/skills/adityaaatiwari-docker-best-practices-anvil)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.