agentleFS
ldaumeldaume/agentic-engineering-harness/skills/infrastructure/multi-stage-dockerfile/SKILL.md

multi-stage-dockerfile

Skill3 starsChanged 3 months agoMITView on GitHub

Creates and reviews secure, cache-friendly multi-stage Dockerfiles for Node, web, backend, and static-site projects. Use when writing Dockerfiles, optimizing image size, separating build/runtime stages, hardening containers, fixing slow Docker builds, or preparing production images.

  • Reads credentials

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use web-design-guidelines and improve-codebase-architecture.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • VercelSkill

    web-design-guidelines

    Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

    Also in 3 projects that use this

  • GoogleSkill

    improve-codebase-architecture

    Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. 0 are common, 12 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this for production-oriented Dockerfiles where build dependencies, runtime dependencies, security, and cache behavior should be …

    line 8
  2. Distinctive:

    Before writing a Dockerfile:

    line 13
  3. Distinctive:

    Read existing Dockerfiles, compose files, CI image build jobs, and deployment docs.

    line 17
  4. Distinctive:

    Do not introduce Alpine, distroless, rootless, or monorepo pruning patterns without checking framework/native dependency compatibility.

    line 20
  5. Distinctive:

    If the image is deployed by CI, align build args, secrets, labels, and tags with that pipeline.

    line 22
  6. Distinctive:

    Keep dependency install before source copy so source changes do not invalidate the dependency cache.

    line 34
  7. Distinctive:

    Use the lockfile with the matching package manager.

    line 39
  8. Distinctive:

    Keep build secrets out of final layers.

    line 41
  9. Very specific:

    Use .dockerignore to exclude node_modules, build output, VCS metadata, local env files, and caches.

    line 42
  10. Very specific:

    Prefer explicit CMD and documented EXPOSE.

    line 44
  11. Distinctive:

    Use health checks only when the deployment platform respects them.

    line 45
  12. Distinctive:

    Add OCI labels if the registry/deploy process uses them.

    line 46
  13. Distinctive:

    Avoid root in the final image when the runtime allows it.

    line 50
  14. Very specific:

    Never bake .env, tokens, SSH keys, or registry credentials into layers.

    line 51
  15. Distinctive:

    Keep package manager caches out of the final image.

    line 52

“Common” is measured: kept by at least 6 in 10 of the 11 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

Multi-Stage Dockerfile

Use this for production-oriented Dockerfiles where build dependencies, runtime dependencies, security, and cache behavior should be explicit.

Project Fit Check

Before writing a Dockerfile:

  1. Detect runtime, package manager, lockfile, build output, server command, and required native dependencies.
  2. Read existing Dockerfiles, compose files, CI image build jobs, and deployment docs.
  3. Preserve the project's base-image policy, registry, and runtime user model.
  4. Do not introduce Alpine, distroless, rootless, or monorepo pruning patterns without checking framework/native dependency compatibility.
  5. If the image is deployed by CI, align build args, secrets, labels, and tags with that pipeline.

Structure

Default shape:

  1. base: shared runtime image and environment
  2. deps: install dependencies from lockfile
  3. build: copy source and build artifacts
  4. runtime: copy only runtime files and run as non-root when possible

Keep dependency install before source copy so source changes do not invalidate the dependency cache.

Rules

  • Use the lockfile with the matching package manager.
  • Copy only needed files between stages.
  • Keep build secrets out of final layers.
  • Use .dockerignore to exclude node_modules, build output, VCS metadata, local env files, and caches.
  • Prefer explicit CMD and documented EXPOSE.
  • Use health checks only when the deployment platform respects them.
  • Add OCI labels if the registry/deploy process uses them.

Security

  • Avoid root in the final image when the runtime allows it.
  • Never bake .env, tokens, SSH keys, or registry credentials into layers.
  • Keep package manager caches out of the final image.
  • Pin base image by digest when supply-chain policy requires reproducibility.
  • Rebuild regularly for base image security patches.

Verification

docker build -t local-test .
docker run --rm local-test <smoke command>

For web services, run the container and hit a health or homepage route.

Red Flags

  • one-stage image with compilers and dev dependencies in production
  • COPY . . before dependency install
  • missing .dockerignore
  • final image runs as root without a reason
  • secrets passed via ARG and kept in image history
  • container command differs from documented deploy command

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.