dockerfile-optimize

dockerfile-optimize is a command for coding agents from sigistry/marketplace. It costs 15 tokens per session (699 once invoked), scanned A, original, MIT.

A command that analyzes and improves a Dockerfile, the recipe used to build a container image. It checks image size, security, and build speed.

In plain words
What is it for?
Use it to review a Dockerfile and its build context, detect configuration issues, and recommend or apply safer, smaller, faster build patterns.
Why use it?
It helps find common container problems such as running as root, unpinned base images, slow cache usage, unnecessary build tools, or secrets stored in image layers.

Command

Part of the ci-incident-medic plugin — 4 skills, 5 commands, 3 agents shipped together

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 commands/sigistry/marketplace/dockerfile-optimize
Clone the repo
git clone --depth 1 https://github.com/sigistry/marketplace

Or install ci-incident-medic, the plugin that ships this one along with the rest of its 4 skills, 5 commands, 3 agents.

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 dockerfile-optimize

README.md
[![agentmods](https://agentmods.dev/badge/commands/sigistry/marketplace/dockerfile-optimize.svg)](https://agentmods.dev/commands/sigistry/marketplace/dockerfile-optimize)
Your own site
<a href="https://agentmods.dev/commands/sigistry/marketplace/dockerfile-optimize"><img src="https://agentmods.dev/badge/commands/sigistry/marketplace/dockerfile-optimize.svg" alt="Measured on agentmods" height="20"></a>
Per session 15 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 699 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 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.00015 $0.00699
Opus 5 $0.00008 $0.00349
Sonnet 5 $0.00003 $0.00140
Haiku 4.5 $0.00002 $0.00070

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

Security

Grade A, and why

dockerfile-optimize scanned grade A with 0 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 3d ago.

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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/ci-incident-medic/commands/dockerfile-optimize.md · 46 lines

How it starts

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

Analyze a Dockerfile and harden it: smaller image, non-root runtime, faster cache-friendly builds. Use this before an image ships or when builds are slow, huge, or flagged by a scanner. $ARGUMENTS is the Dockerfile path; default to ./Dockerfile if omitted.

Process

Step 1: Read the Dockerfile and its context

  • Read the target Dockerfile. Detect the base image and language ecosystem (Node, Python, Go, Java/JVM, Rust, etc.) from FROM and the copied manifests (package.json, requirements.txt/pyproject.toml, go.mod, pom.xml/build.gradle, Cargo.toml).
  • Check whether a .dockerignore exists alongside it.

Step 2: Detect smells

Apply the dockerfile-smells skill. Flag each present:

Smell Cost
Runs as root (no USER) container escape blast radius, violates most policies
latest or unpinned base tag non-reproducible builds, silent base drift
No multi-stage build build toolchain + source shipped in final image
Cache-busting layer order COPY . . before dependency install invalidates cache every edit
Secrets baked into layers tokens/keys recoverable from image history forever
apt-get/apk without cleanup lists and caches bloat the layer
Missing .dockerignore huge build context, secrets/.git sent to daemon
No HEALTHCHECK orchestrator can't detect a wedged-but-running process

Step 3: Apply fixes

  • Launch the dockerfile-hardener agent to rewrite the Dockerfile in place: multi-stage split, pinned base digest, non-root USER, optimal layer ordering, no secrets in layers, minimal packages, and a HEALTHCHECK where it makes sense. The agent also emits a matching .dockerignore.
  • Consult the dockerfile-smells multistage-patterns.md reference for the ecosystem-specific template.

Step 4: Report

Produce these sections:

  • Before / After: the original and hardened Dockerfile side by side (or as a diff).
  • Generated .dockerignore: the file contents.
  • Per-change rationale: a table of change → reason.
  • Expected wins: estimated image-size reduction and the concrete security posture change (e.g. "runs as UID 10001, root filesystem read-only, no build toolchain in final layer"). Frame size numbers as estimates unless the user provides a real docker images measurement.

Read the full file on GitHub · 46 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. 3d ago First seen · 46 lines · 15 tokens per session scan A b63225131ae5

Subscribe to this mod's changes

dockerfile-optimize is a command published in the GitHub repository sigistry/marketplace (3 stars, last pushed today), licensed MIT. It adds 15 tokens to every session and 699 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.