agentleFS
divik-09divik-09/claude-skills-collection/skills/docker-best-practices/SKILL.md

docker-best-practices

Skill1 starsChanged 9 days agoMITView on GitHub

Write, review, and harden Dockerfiles and docker-compose setups for small, fast, secure images. Use whenever the user shares a Dockerfile or compose file, asks to containerize an app, reduce image size, speed up builds, or fix container security or caching problems.

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 2 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run as non-root: create a user and USER app.

    line 15
  2. Distinctive:

    Add a HEALTHCHECK where the platform does not provide one.

    line 19
  3. Very specific:

    Prefer COPY over ADD. Set WORKDIR explicitly.

    line 20
  4. Distinctive:

    Do not publish ports that only other containers need.

    line 24
  5. Very specific:

    Use named volumes for data, and depends_on with health conditions.

    line 25
  6. Very specific:

    Keep secrets out of the compose file.

    line 26

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Docker Best Practices

Dockerfile checklist

  • Pin the base image to a specific version (ideally a digest for production). Never rely on latest.
  • Use small, appropriate bases: -slim, distroless, or alpine (beware musl incompatibilities with some Python/Node native packages).
  • Multi-stage builds: compile or install dev dependencies in a builder stage, copy only artifacts into the final stage.
  • Order layers for cache: copy dependency manifests (requirements.txt, package*.json) and install first, then copy source.
  • Combine and clean: apt-get update && apt-get install -y --no-install-recommends ... && rm -rf /var/lib/apt/lists/* in one RUN.
  • Run as non-root: create a user and USER app.
  • Use .dockerignore to exclude .git, node_modules, .env, build output, tests.
  • Never bake secrets into layers (ARG/ENV/COPY). Use runtime env vars, orchestrator secrets, or BuildKit --mount=type=secret.
  • Exec-form CMD/ENTRYPOINT (["python","app.py"]) so signals reach the process; consider tini/--init.
  • Add a HEALTHCHECK where the platform does not provide one.
  • Prefer COPY over ADD. Set WORKDIR explicitly.

Compose checklist

  • Do not publish ports that only other containers need.
  • Use named volumes for data, and depends_on with health conditions.
  • Keep secrets out of the compose file; use .env (git-ignored) or secrets.
  • Set resource limits and restart policy where relevant.
  • Separate dev overrides (compose.override.yml) from production config.

Output

Return a corrected Dockerfile with inline comments on each change, a .dockerignore if missing, and a brief list of remaining risks (image scanning with Trivy/Grype, SBOM, update cadence). Estimate size or build-time impact only when you can justify it.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.