No. 113 Ship it

Docker Rules

Use when the change has to leave the machine

  • Claude Code
  • Codex
  • Cursor
  • Ship it

Prompt

# Docker Rules

Expert Docker practitioner. Minimal, secure, reproducible images.

## Dockerfile
- Pin versions: FROM node:20.11-alpine3.19 (never :latest)
- Multi-stage builds for compiled languages
- Layer cache: copy package files → install → copy source
- Combine RUN commands with && to minimize layers
- USER non-root before CMD
- HEALTHCHECK on all services
- COPY --chown=appuser:appuser for file ownership

## Security
- Never run as root
- No secrets in Dockerfile or image layers
- No .env files copied into image
- Scan with docker scout or trivy in CI

## .dockerignore
- Always present: node_modules, .git, *.log, .env*, test files

## Volumes
- Named volumes for persistence
- Bind mounts for dev only, never production

## Networking
- Custom bridge networks, not host networking
- Reference services by name in compose

## Logging
- Always stdout/stderr — never log to files inside container

## Forbidden
- No :latest tags in production
- No ADD when COPY works
- No root user in production
- No secrets in build args or image layers

When to use

“Docker Rules” fits when the change has to leave the machine, because it says “Docker Rules”, and it is written to stay in force on later turns rather than to finish one task.

With “Docker Rules” loaded, the user message can be as small as “fix the empty-cart total in src/cart.js and do not touch the test runner”, because “Docker Rules” is already in force.

When not to use

Leave “Docker Rules” unused when the change is still a local question and nothing is ready to ship, because “Docker Rules” points the other way

How to run it

Claude Code

Claude Code loads “Docker Rules” from .claude/rules on later sessions, so “Docker Rules” survives a new chat, which a one-off paste does not.

Codex

Codex keeps “Docker Rules” only if you put “Docker Rules” in AGENTS.md, or in AGENTS.override.md beside the directory that should inherit it. A paste that is not saved is gone next thread.

Cursor

Cursor keeps “Docker Rules” by saving “Docker Rules” as .cursor/rules. The chat transcript alone will not reload it tomorrow.

Comparison

对比待补

This before-and-after was not run on this machine.

Related

来源:PatrickJS awesome-cursorrules · https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/docker.mdc · CC0-1.0 · 2026-12-01