agentleFS
Lukk17Lukk17/agent-standards/.agents/skills/docker-patterns/SKILL.md

docker-patterns

Skill1 starsChanged 57 days agoMITView on GitHub

Docker and Compose standards for multi-stage builds, pinned base images, non-root runtime users, named volumes, network isolation, build-time and runtime secrets, and the Trivy, SBOM and cosign supply-chain gate. Use when you say "write a Dockerfile for this service", "set up compose for local dev", "my container cannot reach the database", "shrink this image", or "scan and sign this image before we push". Not for Kubernetes manifests and rollout strategy, use `deployment-patterns`.

  • Reads credentials

32 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use content-hash-cache-pattern, carrier-relationship-management and 7 more.

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.
  • InfopibeSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 10 projects that use this

  • InfopibeSkill

    carrier-relationship-management

    Codified expertise for managing carrier portfolios, negotiating freight rates, tracking carrier performance, allocating freight, and maintaining strategic carrier relationships. Informed by transportation managers with 15+ years experience. Includes scorecarding frameworks, RFP processes, market intelligence, and compliance vetting. Use when managing carriers, negotiating rates, evaluating carrier performance, or building freight strategies.

    Also in 8 projects that use this

  • saxon-ySkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 9 projects that use this

  • +6 more from Infopibe

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

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

    Never use ubuntu:latest or debian:latest as a runtime base.

    line 114
  2. Distinctive:

    Create a user in the image and switch to it before the runtime stage ends.

    line 120
  3. Distinctive:

    Put a database on its own network rather than relying on nobody connecting to it, and bind published ports to loopback so they are not …

    line 188
  4. Distinctive:

    Verify before deploy, in the pipeline, not by hand:

    line 276
  5. Distinctive:

    Keep the last 10 tagged releases, auto-delete untagged images after 7 days, and implement it as a registry lifecycle policy rather than a …

    line 289

“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

Docker Patterns

How a container image stays small, reproducible, and safe to run: a pinned base, a build split into stages, a non-root user, no secret baked into a layer, and a scan plus a signature before it is trusted anywhere. Compose then wires those images into a local stack that behaves like the real one.

Baseline: Docker Engine 29.3 and Docker Compose v5.1 (both verified locally). The Compose v1 docker-compose command is gone, every command below is docker compose.


When to activate

  • Writing or reviewing a Dockerfile or a Compose file.
  • Setting up or debugging a local multi-service development stack.
  • Shrinking an image, or fixing one that rebuilds everything on every change.
  • Hardening a container: user, capabilities, filesystem, secrets.
  • Adding image scanning, an SBOM, or signing to a pipeline.
  • Diagnosing container networking, DNS, or volume behaviour.

When not to activate

  • Writing Kubernetes manifests, probes, or rollout strategy, use deployment-patterns.
  • Configuring hosts rather than containers, use ansible.
  • Writing the entrypoint script itself, use bash or powershell.
  • Instrumenting the application inside the container, use observability-and-logging.
  • Reviewing the application's own authentication or input handling, use security-review.

Named volumes only

An anonymous volume (- /app/node_modules) gets a random hash for a name. Nothing can back it up, target it, inspect it, or share it, and it survives docker compose down as a dangling volume consuming disk invisibly. In production it ties data to a container lifecycle instead of a managed resource.

Pass:

volumes:
  - node_modules:/app/node_modules

Fail:

volumes:
  - /app/node_modules

Build in stages, ship the last one

A multi-stage build keeps compilers, dev dependencies, and build caches out of the shipped image. Copy dependency manifests before source so a code change does not invalidate the dependency layer.

Pass:

COPY package.json package-lock.json ./
RUN npm ci
COPY . .

Fail:

COPY . .
RUN npm ci

Full reference Dockerfiles for Node, Go, and Python, plus the apt-get, OCI label, and build-secret rules, are in references/dockerfiles.md.


Pin the base image

:latest makes a build unreproducible and silently changes the runtime under you. Pin a specific tag, and pin a digest where the registry supports it.

Pass:

FROM node:24.11-alpine3.23

Fail:

FROM node:latest

Pick the smallest base that can actually run the artefact:

WorkloadPreferred base
Compiled binaries (Go, Rust)gcr.io/distroless/static-debian13:nonroot or scratch
JVM (Spring Boot)gcr.io/distroless/java21-debian13:nonroot
Node.jsnode:24.11-alpine3.23
Pythonpython:3.14-slim

Distroless publishes no version tags, only latest, nonroot and their debug variants, so its pin is the Debian suffix in the name plus a digest.

Never use ubuntu:latest or debian:latest as a runtime base.


Run as a non-root user

Create a user in the image and switch to it before the runtime stage ends. A container escape from root is a host compromise, from an unprivileged user it usually is not.

Pass:

RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
USER appuser

Fail:

CMD ["node", "dist/server.js"]

Harden the runtime from Compose as well, dropping every capability and adding back only what the process genuinely needs:

services:
  app:
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
      - /app/.cache
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE

NET_BIND_SERVICE is only needed when the process binds a port below 1024. Listen on a high port and drop it too.


No secret in an image or a compose file

Inject secrets at runtime through the environment or a Docker secret. Anything set with ENV or ARG is readable from the image history by anyone who can pull it.

Pass:

services:
  app:
    env_file:
      - .env
    environment:
      - API_KEY

Fail:

ENV API_KEY=sk-proj-xxxxx

- API_KEY with no value inherits the variable from the host environment, so the value never enters a committed file. .env is gitignored. For build-time credentials use --mount=type=secret, covered in references/dockerfiles.md.


Isolate what should not be reachable

Put a database on its own network rather than relying on nobody connecting to it, and bind published ports to loopback so they are not exposed to the host's network.

Pass:

services:
  db:
    ports:
      - "127.0.0.1:5432:5432"
    networks:
      - backend-net

Fail:

services:
  db:
    ports:
      - "5432:5432"

Omit ports on internal services in production entirely. Compose service names resolve inside the network, so nothing needs a published port to talk to them.


.dockerignore

Without one, the whole working tree goes into the build context, which slows every build and risks copying .env and .git into a layer. Create it next to the Dockerfile.

Pass:

node_modules
dist
build
*.log
.git
.gitignore
.env
.env.*
coverage
**/*.test.ts
**/*.spec.ts
tests/

Fail:

node_modules

Supply chain: scan, bill of materials, signature

This section is canonical for the repository. Other skills point here rather than restating it.

Scan every image in CI before it is pushed, and fail the build on a fixable critical or high finding:

trivy image --exit-code 1 --severity CRITICAL,HIGH myimage:tag

Store the scan report as a CI artifact, so a later question about what was known at release time has an answer.

Generate a Software Bill of Materials after push:

syft myimage:tag -o cyclonedx-json > sbom.json

Attach it to the pushed image as a signed attestation, so the SBOM travels with the image in the registry:

cosign attest --key cosign.key --type cyclonedx --predicate sbom.json myregistry/myimage:tag

Sign every production image after push:

cosign sign --key cosign.key myregistry/myimage:tag

Verify before deploy, in the pipeline, not by hand:

cosign verify --key cosign.pub myregistry/myimage:tag

A signature nothing verifies proves nothing. The verify step belongs in the deploy job, gating it, and a cluster policy should reject an unsigned image outright.


Registry retention

Keep the last 10 tagged releases, auto-delete untagged images after 7 days, and implement it as a registry lifecycle policy rather than a cleanup script somebody remembers to run.

Pass:

ECR lifecycle policy: keep 10 images tagged with prefix "v", expire untagged after 7 days.

Fail:

docker system prune -a

Reference files

Open thisFor
references/dockerfiles.mdFull multi-stage Dockerfiles for Node, Go and Python, plus apt-get layering, OCI labels, and build-time secrets
references/compose-and-debugging.mdA complete local stack, override files, network isolation, volume strategies, and the commands for debugging containers and networking

Related skills

  • deployment-patterns for Kubernetes, rollout strategy, and the pipeline these images move through.
  • observability-and-logging for the health, readiness, and log output the container emits.
  • bash and powershell for entrypoint and healthcheck scripts.
  • ansible for configuring the hosts the daemon runs on.
  • security-review before shipping an image that handles credentials or faces the internet.

Checklist

  • Every base image pinned to a specific tag, never :latest.
  • Build split into stages, dependency manifests copied before source.
  • Runtime stage runs as a created non-root user.
  • HEALTHCHECK declared.
  • .dockerignore present next to the Dockerfile and excludes .git, .env, and tests.
  • No secret in ENV, ARG, or a committed compose file.
  • Named volumes only, no anonymous volume anywhere.
  • Internal services on their own network, published ports bound to loopback or omitted.
  • cap_drop: [ALL], no-new-privileges, and a read-only root filesystem where the process allows it.
  • Trivy scan gates the push, the report is archived, and an SBOM is generated and attested to the image.
  • Production images are signed and the signature is verified by the deploy job.
  • Registry retention enforced by a lifecycle policy.

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.