docker-conventions

A set of rules for writing Dockerfiles and container configuration. Docker packages an application and its dependencies so it can run consistently in different environments.

In plain words
What is it for?
Use it when choosing base images, creating multi-stage builds, improving build-cache use, running as a non-root user, keeping secrets out of image layers, and adding health checks.
Why use it?
It helps avoid oversized, insecure, difficult-to-cache, or unreliable container builds.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/andr-ca/agentharness/docker-conventions
Clone the repo
git clone --depth 1 https://github.com/andr-ca/agentharness

Made for: Cursor.

Per session 43 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,211 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00043 $0.01211
Opus 5 $0.00022 $0.00606
Sonnet 5 $0.00009 $0.00242
Haiku 4.5 $0.00004 $0.00121

Measured yesterday against content hash a461c582ddc9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

docker-conventions scanned grade B with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletemediumDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

packages: `apt-get install -y ... && rm -rf /var/lib/apt/lists/*`

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- Don't install `curl`, `wget`, or debugging tools in production images.
.cursor/rules/docker-conventions.mdc · 172 lines

How it starts

The opening of the file, as written. The whole thing — 172 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Docker Conventions

Best practices for Dockerfiles and container configurations. Focus areas: image size, build cache efficiency, security, and production readiness.

Base images

  • Use official images with a pinned version tag: python:3.12-slim, node:22-alpine, golang:1.24-alpine.
  • Prefer slim (Debian-based, small) or alpine (even smaller, musl libc) variants. Avoid latest — it changes without notice.
  • For production, prefer distroless or scratch (Go static binaries) to minimise the attack surface.
# Good: specific version, minimal base
FROM python:3.12-slim

# Bad: unpinned, full Debian base
FROM python:latest

Multi-stage builds

Use multi-stage builds to keep the production image small — the build tools (compilers, test runners, dev dependencies) stay in the build stage and never reach the final image.

# Stage 1: build
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: production
FROM node:22-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
USER node
CMD ["node", "dist/index.js"]

Layer caching

Docker caches layers until a layer (or one of its inputs) changes. Copy dependency files before source code so the dependency install step is cached across code-only changes.

# Good: dependency install cached when only code changes
COPY package*.json ./
RUN npm ci
COPY . .         # ← only invalidates layers from here down

# Bad: copies all source first — dependency install re-runs on every code change
COPY . .
RUN npm install

Security

Never embed secrets in a Dockerfile or in a layer. Secrets baked into a layer remain accessible in the image history even if deleted in a later layer.

# WRONG: secret in a layer (visible via `docker history`)
RUN echo "API_KEY=abc123" > /app/.env

# RIGHT: pass secrets at runtime via environment variable or a secret mount
# docker run -e API_KEY=$API_KEY ...
# or use BuildKit secrets for build-time:
RUN --mount=type=secret,id=api_key cat /run/secrets/api_key > /tmp/key

Read the full file on GitHub · 172 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 172 lines · 43 tokens per session scan B a461c582ddc9

Subscribe to this mod's changes

docker-conventions is a cursor rule published in the GitHub repository andr-ca/agentharness (1 stars, last pushed yesterday), licensed MIT. It adds 43 tokens to every session and 1,211 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it B with 2 findings (recursive force delete, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.