agentleFS
leroyguillaumeleroyguillaume/claude/docker-conventions/SKILL.md

docker-conventions

Skill7 starsChanged 2 days agoMITView on GitHub

Dockerfiles: base images, multi-stage builds, non-root USER, hadolint and Trivy; Compose file naming. TRIGGER when: editing or creating a `Dockerfile`, `Containerfile`, `.dockerignore` or Compose file (`docker-compose.yaml`, `compose.yaml`); user asks about base images, image size, container CVEs, non-root users, hadolint or naming a compose file. SKIP when: no Dockerfile or Compose file is touched and the user isn't asking about container builds.

  • Pipes a download into a shell
  • Deletes or force-pushes
  • Installs packages

3 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

9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

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

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

    Create a .dockerignore file to exclude unnecessary files from the build context (.git/, node_modules/, *.log, README.md, etc.).

    line 18
  2. Very specific:

    use the upstream :nonroot tag and USER nonroot:nonroot.

    line 40
  3. Very specific:

    Follow Linux (FHS) path conventions, with <appname> the project name:

    line 87
  4. Very specific:

    Create a dedicated non-root user and group named after the app (use a short, recognisable name if the project name is long or not a valid …

    line 92
  5. Very specific:

    Verify extraction actually works before trusting it: LOG_LEVEL=debug npx --package renovate -- renovate --platform=local --dry-run=extract.

    line 152
  6. Very specific:

    Never end a Dockerfile without an explicit non-root USER.

    line 185
  7. Very specific:

    Never run as root in the final image, even "temporarily".

    line 186
  8. Very specific:

    Name the file docker-compose.yaml: Always use this exact name, with the .yaml extension (not .yml), and not the shorter compose.yaml / …

    line 204
  9. Very specific:

    If a repo already has a compose.yaml, compose.yml, or docker-compose.yml, rename it to docker-compose.yaml rather than leaving the variant …

    line 209

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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 conventions

Always:

  • Create a .dockerignore file to exclude unnecessary files from the build context (.git/, node_modules/, *.log, README.md, etc.).
  • A Compose file is named per "Compose files" below.
  • Pick the smallest runtime base image the app can actually run on. Every package in the final image is a CVE waiting to be reported against you, and the fastest way to fix a vulnerability is to not ship the package. Walk down this ladder and stop at the first rung that works:
    1. scratch — statically linked binaries (Rust with musl, Go with CGO_ENABLED=0). Zero packages, zero CVEs, nothing to patch.
    2. Distroless (gcr.io/distroless/static, .../base, .../cc) — when you need libc, TLS roots, or /etc/passwd but no shell or package manager. Prefer the :nonroot variants.
    3. alpine — when you genuinely need a shell or a couple of apk packages.
    4. *-slim (debian:*-slim, python:*-slim) — when glibc or a distro runtime is unavoidable. Full distro images (debian, ubuntu, python:3.13, node:22) are a builder-stage-only thing; they never appear in the last FROM.
  • Always multi-stage. Compilers, headers, package managers, and dev dependencies stay in the builder; the runtime stage gets the artefact and nothing else. If the final stage installs a toolchain, the split is wrong.
  • Distroless and scratch have no groupadd/useradd. Two options, both fine, and both land on the same UID 65532 as the rule below:
    • use the upstream :nonroot tag and USER nonroot:nonroot;
    • or create the user in the builder stage and copy /etc/passwd and /etc/group over. Either way the final stage still ends with an explicit non-root USER. The copied entry names /usr/sbin/nologin, a binary the final image does not contain — harmless, since an image with no shell and no sshd has no login path to refuse in the first place.
  • Scan the built image in CI (trivy image) and fail the build per the gate policy in ci-conventions, which also owns the daily re-scan of the published image. A skinny base is what makes that gate cheap enough to keep enabled.
  • Scan the Dockerfile itself with trivy config, and fix every finding. These are the DS-xxxx checks (DS-0002 running as root, DS-0026 missing HEALTHCHECK, DS-0001 :latest tag, DS-0009 relative WORKDIR, …). Treat them as errors and fix at the source — no self-authorised ignores (ci-conventions). It is a pre-commit hook, so it also gates CI through quality; a repo: local, language: system hook, never a Docker-backed one (pre-commit-conventions):
    - repo: local
      hooks:
        - id: trivy-dockerfile
          name: trivy config (Dockerfile)
          entry: trivy config --exit-code 1 Dockerfile
          language: system
          pass_filenames: false
          files: (^|/)(Docker|Container)file$
    trivy config takes one target, so a repo with several Dockerfiles gets one hook per file rather than passed filenames: set entry and files to that file's path (docker/api/Dockerfile, Containerfile).
  • trivy does not replace hadolint. Run both. They overlap on the obvious stuff (absolute WORKDIR, cd in RUN, --no-install-recommends), but each catches things the other is blind to:
    • Only hadolint: apk package version pinning (DL3018) — the pinning rule below has no Trivy equivalent, which by itself settles the question; apt list cleanup (DL3009); JSON notation for ENTRYPOINT/CMD (DL3025); and ShellCheck on every RUN line (SC2086 unquoted expansion, etc.), which Trivy does not do at all.
    • Only trivy: missing HEALTHCHECK (DS-0026), plus severity levels and the same report format as image/IaC scanning.
  • Keep the runtime lean beyond the base image too: --no-install-recommends for apt, --no-cache for apk, no curl/wget/bash "just for debugging", and health checks that use the app itself rather than an extra binary.
  • Language packages come from the lockfile (npm ci, uv sync --locked, cargo build --locked), never curl … | sh or an unpinned pip install: the install rule is ci-conventions'.
  • Follow Linux (FHS) path conventions, with <appname> the project name:
    • Build in /usr/local/src/<appname> (the builder stage WORKDIR).
    • Binary installed to /usr/local/bin/ (on PATH).
    • Config, if the app has any, under /etc/<appname>/.
    • Any mutable state under /var/lib/<appname>/.
  • Create a dedicated non-root user and group named after the app (use a short, recognisable name if the project name is long or not a valid Linux username), with UID 65532 and GID 65532, and end the Dockerfile with a USER directive. The account's other properties — nologin shell, locked password, no group it does not need — are system-user-conventions; the UID is the one thing that differs here, and the next paragraph says why. Why 65532 and not 1000: UID/GID must be > 10000 (Trivy KSV-0020 / KSV-0021). Without user namespaces, a container UID is a host UID, and 1000 is the first human account on virtually every Linux box — so a container escape, a hostPath mount, or a shared NFS export lands with that user's identity. 65532 is the specific high UID upstream already agreed on (distroless:nonroot, Chainguard), which keeps the number identical whether you inherit the user or create it. Avoid 65534 — that's nobody/nogroup, shared by every unmapped process and squashed-to by NFS. Example (app myapp):
    WORKDIR /usr/local/src/myapp
    # ... build, producing /usr/local/src/myapp/target/release/myapp ...
    
    RUN groupadd --system --gid 65532 myapp \
     && useradd  --system --uid 65532 --gid myapp \
          --home /nonexistent --no-create-home --shell /usr/sbin/nologin myapp
    COPY --from=builder \
         /usr/local/src/myapp/target/release/myapp /usr/local/bin/myapp
    USER myapp
    ENTRYPOINT ["/usr/local/bin/myapp"]
  • chown only what the app writes — never the binary. COPY without --chown lands root:root 0755, which is what an executable should be: the process needs to execute it, not to own it, and a service that can rewrite its own binary rewrites it once and is still there after every restart. Give the app user only its state and cache paths, and prefer readOnlyRootFilesystem: true at the orchestrator (see helm-conventions) so the question stops arising.
  • --home follows system-user-conventions: the state directory, or /nonexistent with --no-create-home.
  • Lint every Dockerfile with hadolint: the hadolint hook from the hadolint/hadolint repo, never the Docker-backed hadolint-docker.
  • Fix every hadolint warning at the source. A green run is the only acceptable end state.
  • Pin apk package versions (apk add pkg=1.2.3-r4) — this is DL3018, and the answer is to pin, not to silence. Keeping the pins current is Renovate's job, not a reason to skip them. Annotate each one so Renovate can see it:
    # renovate: datasource=repology depName=alpine_3_24/bash versioning=loose
    RUN apk add --no-cache bash=5.3.9-r1
    Notes that save an hour of debugging:
    • depName is <repology-repo>/<package>, and the repo carries the distro release (alpine_3_24, debian_13). It does not follow a base-image bump on its own — when the base moves to a new release, the annotations must move with it or Renovate silently keeps resolving against the old one.
    • Multi-stage builds often sit on different distro releases per stage (a toolchain image and a runtime image rarely move in lockstep). Check each stage (cat /etc/alpine-release) and annotate per stage.
    • Take the version from the image itself (apk list <pkg> / apt-cache policy <pkg>), not from Repology's version field — Repology normalises (5.3.p9), and only its origversion (5.3.9-r1) is the string apk will accept.
    • Verify extraction actually works before trusting it: LOG_LEVEL=debug npx --package renovate -- renovate --platform=local --dry-run=extract.
  • Do not pin apt package versions on Debian/Ubuntu — leave DL3008 ignored. This is a deliberate exception to the rule above, not an oversight, and # hadolint ignore=DL3008 is pre-authorised here (the "never silence a rule on your own initiative" rule below does not apply to this one code). Two reasons:
    • The pin rots into a build failure. deb.debian.org serves exactly one version of each package per suite: the current one. The moment a security update or point release lands, curl=8.14.1-2+deb13u4 stops existing and every build breaks — including builds of tags that used to work.
    • A frozen pin means frozen CVEs. A stable suite only moves for security updates, so an unpinned apt-get install on a rebuild picks up precisely the patches you want — while a pin freezes the vulnerability until a human notices. That is backwards for an image you are also scanning with Trivy. Reproducibility is recovered at the layer where it actually works: pin the base image by digest and rebuild on a schedule. Not with apt pins. The ignore sits on the RUN it covers, so a third-party apt install elsewhere in the file is still checked:
    # hadolint ignore=DL3008
    RUN apt-get update \
     && apt-get install --yes --no-install-recommends ca-certificates \
     && rm -rf /var/lib/apt/lists/*
    What still gets pinned, because those pools keep old versions: third-party apt repos (download.docker.com, PostgreSQL, NodeSource), PyPI, npm, and GitHub release assets. Hoist third-party apt versions into ARGs at the top of the Dockerfile so every version knob lives in one place.

Never:

  • Never end a Dockerfile without an explicit non-root USER.
  • Never run as root in the final image, even "temporarily".
  • Never ship a full distro image as the runtime stage because it was convenient, because the builder already used it, or because "we might need to exec into it". Debugging is what docker debug, ephemeral containers, and a separate -debug tag are for.
  • Never use a floating tag (:latest, :3, :bookworm) in a FROM. Pin the specific version, and pin by digest where the registry supports it (image:1.2.3@sha256:…) — the dependency bot keeps both current. A floating tag means the image you scanned is not the image you shipped.
  • Never silence a scanner or hadolint finding on your own initiative — the rule is in ci-conventions. A # hadolint ignore=DLxxxx goes in only when the user expressly asked for that specific code. The single standing exception is DL3008 (apt version pinning), which is pre-authorised — see the apt rule above. Everything else, including DL3018, still needs an explicit ask.

Compose files

  • Name the file docker-compose.yaml. Always use this exact name, with the .yaml extension (not .yml), and not the shorter compose.yaml / compose.yml form. Compose discovers all of these automatically, so the choice is about consistency: every Compose file across every project carries the same recognisable name.
  • If a repo already has a compose.yaml, compose.yml, or docker-compose.yml, rename it to docker-compose.yaml rather than leaving the variant in place.
  • YAML inside the file follows yaml-conventions.

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.