agentleFS
RuneStone-TechRuneStone-Tech/optimize-anything/skills/devops/docker/SKILL.md

docker-optimizer

Skill1 starsChanged 8 days agoMITView on GitHub

Audit and optimize Docker and Compose projects (Docker Engine 29, BuildKit/Buildx, Compose v2) for image size and layer count, build cache and multi-stage builds, runtime security (non-root, read-only, capabilities, secrets), supply-chain provenance/SBOM/scanning, compose healthchecks/resource limits/networking, startup and pull performance, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions a huge/slow Docker image, Dockerfile review, multi-stage builds, BuildKit cache mounts, docker compose, container security, rootless Docker, image scanning/SBOM, `docker buildx`, or "optimize my Docker setup" -- even if they never say audit or optimize.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    Run python <skill-dir>/scripts/audit.py <repo-root> -- static scan for floating tags, missing users/healthchecks, apt/npm cache waste, …

    line 15
  2. Very specific:

    Read references/tooling.md once: what can be measured here (docker buildx build, docker image history, dive, docker scout/Trivy/Grype, …

    line 17
  3. Very specific:

    Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode.

    line 41
  4. Distinctive:

    Run as non-root: No secrets in layers; read-only rootfs where possible.

    line 60
  5. Very specific:

    Docs move: Check the Engine 29/BuildKit/Compose docs for the installed version.

    line 65

“Common” is measured: kept by at least 6 in 10 of the 3 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 Optimizer

Audit a Docker/Compose setup, report what is slow, large or unsafe and why, agree a plan, then change it. Order: evidence, approval, edits. Image and runtime changes affect deployability and security; nothing is edited before approval.

Workflow

1. Scope (quick)

  • Find the Dockerfiles/compose files and record: Docker Engine/BuildKit version, base images, build context, target platforms, registry, runtime user, orchestrator (Compose/K8s/PaaS), and deploy command.
  • Run python <skill-dir>/scripts/audit.py <repo-root> -- static scan for floating tags, missing users/healthchecks, apt/npm cache waste, secrets, privileged/host mounts, docker.sock exposure, compose limits and build-cache gaps, with file:line evidence. Use --json to post-process.
  • Classify the pain: image size/pull time, build time/cache, startup, runtime security, compose reliability, or supply chain. Ask which hurts if unclear.
  • Read references/tooling.md once: what can be measured here (docker buildx build, docker image history, dive, docker scout/Trivy/Grype, Compose logs).

2. Audit

The script finds cheap leads; you find the rest by reading the Dockerfile, .dockerignore, compose file and runtime entrypoint. Load only what applies:

AreaReference
Base images, multi-stage, layers, cache mounts, Buildxreferences/build-images.md
Compose services, healthchecks, limits, networking, entrypointsreferences/compose-runtime.md
Non-root, secrets, capabilities, rootless, provenance/SBOM/scanningreferences/security-supply-chain.md
Pull/start performance, image size, registry/cache, observabilityreferences/performance-observability.md
Measurement and honest reportingreferences/tooling.md

Measure, never guess. Build the real target with BuildKit, compare docker image history/dive and cold-pull times, run the container with production limits and measure startup/health. A clean build cache hides transfer and layer costs; report cold and warm.

Mark each finding Confirmed (build/image inspect/runtime evidence) or Suspected (needs measuring).

3. Report

Fill assets/report-template.md, save it as DOCKER_OPTIMIZATION_REPORT.md in the project root, and show the user. Five-line summary, findings table by impact/effort, then per-finding detail (evidence, why it hurts, fix, risk, rollback). Group near-duplicates.

4. Plan -- then stop for approval

Use plan mode: EnterPlanMode (load with ToolSearch if deferred), write the plan, present with ExitPlanMode; if unavailable show it in chat and wait for an explicit "go". Structure:

  1. Quick wins -- pin images, add .dockerignore, reorder layers, npm ci/pip --no-cache-dir, clean apt lists, non-root USER, exec-form CMD, healthcheck, compose limits. Low risk.
  2. Structural -- multi-stage build, distroless/slim runtime, cache mounts, Buildx cache import/export, compose healthchecks/depends_on, read-only rootfs/cap drop, secrets mounts, split build/runtime images. Name each behavior change.
  3. Heavy -- base-image family change, rootless/userns-remap, multi-arch, registry/SBOM policy, orchestrator migration. Separately approved. Each step: files touched, expected effect, how to verify, how to roll back.

5. Fix

Only approved items, in small groups. After each: docker buildx build for the target platform, docker run health/startup check, compose config/up, and the relevant scan. A break must trace to one change. Do not mix a base-image migration with optimization edits. If a change alters the runtime user, entrypoint, exposed ports or secrets, stop and ask.

6. Verify and wrap up

Re-measure the same target: image size (compressed/uncompressed), layer count, cold build/pull/start, cache hit, CPU/memory under load, scan findings and SBOM/provenance. State plainly what could not be measured. End with deferred items and one suggested next step.

Principles

  • The smallest image is the one without build tools. Multi-stage + minimal runtime.
  • Cache is layer order. Copy manifests/lockfiles before source; use BuildKit cache mounts.
  • Run as non-root. No secrets in layers; read-only rootfs where possible.
  • Pin what you ship. Tags/digests, not latest; reproducible builds.
  • Compose is production config too. Healthchecks, limits, dependencies and networks are not optional.
  • Scan and sign. SBOM/provenance and a scanner in CI; a clean image is part of the artifact.
  • Measure cold and warm. Build cache, pull time and startup are different costs.
  • Docs move. Check the Engine 29/BuildKit/Compose docs for the installed version.

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.