writing-dockerfiles

writing-dockerfiles is a skill for Claude Code from ancoleman/ai-design-components. It costs 54 tokens per session (3,439 once invoked), scanned D, original, MIT.

A guide to writing Dockerfiles, which are instructions for packaging an application and its dependencies into a Docker container. It includes patterns for Python, Node.js, Go, Rust, and Java projects.

In plain words
What is it for?
Use it to containerize applications, improve existing Dockerfiles, create multi-stage builds, add build caching, and run containers with fewer security risks.
Why use it?
It helps keep container builds smaller, safer, and easier to run consistently. It also addresses separating build tools from the final runtime and preventing secrets from leaking into images.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the devops-skills plugin — 6 skills shipped together

Good fit Use it to containerize applications, improve existing Dockerfiles, create multi-stage builds, add build caching, and run containers with fewer security risks.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ancoleman/ai-design-components/writing-dockerfiles
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.

Any agent
npx skills add ancoleman/ai-design-components --skill writing-dockerfiles
Clone the repo
git clone --depth 1 https://github.com/ancoleman/ai-design-components

Made for: Claude Code.

Or install devops-skills, the plugin that ships this one along with the rest of its 6 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for writing-dockerfiles

README.md
[![agentmods](https://agentmods.dev/badge/skills/ancoleman/ai-design-components/writing-dockerfiles/github.svg)](https://agentmods.dev/skills/ancoleman/ai-design-components/writing-dockerfiles)
Your own site
<a href="https://agentmods.dev/skills/ancoleman/ai-design-components/writing-dockerfiles"><img src="https://agentmods.dev/badge/skills/ancoleman/ai-design-components/writing-dockerfiles/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for writing-dockerfiles

Your own site · 80×15
<a href="https://agentmods.dev/skills/ancoleman/ai-design-components/writing-dockerfiles"><img src="https://agentmods.dev/badge/skills/ancoleman/ai-design-components/writing-dockerfiles.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 54 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,439 The whole file, excluding the scripts and references it only reads on demand.
Security scan D 3 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00054 $0.03439
Opus 5.5 $0.00022 $0.01376
Sonnet 5.5 $0.00011 $0.00688
Haiku 4.5 $0.00005 $0.00344

Measured 1mo ago against content hash 588e76add5cb, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade D, and why

writing-dockerfiles scanned grade D with 3 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 1mo ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/analyze_image_size.sh, scripts/validate_dockerfile.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

Asks for rootmediumPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

- Run as root in production

Recursive force deletehighDestructive command

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

rm -rf src

Makes network callslowCapability

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

CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
skills/writing-dockerfiles/SKILL.md · 473 lines

How it starts

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

Writing Dockerfiles

Create production-grade Dockerfiles with multi-stage builds, security hardening, and language-specific optimizations.

When to Use This Skill

Invoke when:

  • "Write a Dockerfile for [Python/Node.js/Go/Rust] application"
  • "Optimize this Dockerfile to reduce image size"
  • "Use multi-stage build for..."
  • "Secure Dockerfile with non-root user"
  • "Use distroless base image"
  • "Add BuildKit cache mounts"
  • "Prevent secrets from leaking in Docker layers"

Quick Decision Framework

Ask three questions to determine the approach:

1. What language?

  • Python → See references/python-dockerfiles.md
  • Node.js → See references/nodejs-dockerfiles.md
  • Go → See references/go-dockerfiles.md
  • Rust → See references/rust-dockerfiles.md
  • Java → See references/java-dockerfiles.md

2. Is security critical?

  • YES → Use distroless runtime images (see references/security-hardening.md)
  • NO → Use slim/alpine base images

3. Is image size critical?

  • YES (<50MB) → Multi-stage + distroless + static linking
  • NO (<500MB) → Multi-stage + slim base images

Core Concepts

Multi-Stage Builds

Separate build environment from runtime environment to minimize final image size.

Pattern:

# Stage 1: Build
FROM build-image AS builder
RUN compile application

# Stage 2: Runtime
FROM minimal-runtime-image
COPY --from=builder /app/binary /app/
CMD ["/app/binary"]

Benefits:

  • 80-95% smaller images (excludes build tools)
  • Improved security (no compilers in production)
  • Faster deployments
  • Better layer caching

Base Image Selection

Decision matrix:

Language Build Stage Runtime Stage Final Size
Go (static) golang:1.22-alpine gcr.io/distroless/static-debian12 10-30MB
Rust (static) rust:1.75-alpine scratch 5-15MB
Python python:3.12-slim python:3.12-slim 200-400MB
Node.js node:20-alpine node:20-alpine 150-300MB
Java maven:3.9-eclipse-temurin-21 eclipse-temurin:21-jre-alpine 200-350MB

Read the full file on GitHub · 473 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. 1mo ago First seen · 473 lines · 54 tokens per session scan D 588e76add5cb

Subscribe to this mod's changes

writing-dockerfiles is a skill published in the GitHub repository ancoleman/ai-design-components (525 stars, last pushed 10mo ago), licensed MIT. It adds 54 tokens to every session and 3,439 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it D with 3 findings (asks for root, recursive force delete, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.