# Dockerfile Optimizer — analyzer + hardened templates

> Shrink image sizes and accelerate build caching with automated multi-stage Dockerfile refactoring.

Dockerfile Optimizer — analyzer + hardened templates is a free AI agent skill on Agensi by FF, in DevOps & Cloud. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [FF](https://www.agensi.io/creators/f-code)
- Category: [DevOps & Cloud](https://www.agensi.io/skills/devops-cloud)
- Uses: 4
- Version: 1.1
- Last updated: 2026-09-04
- Security: scan passed (2026-09-04); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/dockerfile-optimizer-analyzer-hardened-templates
- Tags: devops, docker, ci-cd, security-hardening, infrastructure-as-code

## About this skill

The problem

Docker images are often bloated, slow to build and run as root. Most Dockerfiles copy the whole source before installing dependencies, so every code change reinstalls everything, and compilers ship to production.

What this skill does

It makes the agent prove the result instead of describing it. scripts/analyze.py (python3, no dependencies, read-only: it only reads the Dockerfile and prints a report) scores any Dockerfile 0-100 against 12 rules: root user, :latest or untagged base, secrets in ENV/ARG, COPY . . before dependency install, apt cache left in the layer, npm install instead of npm ci, remote scripts piped into a shell, ADD for local files, missing HEALTHCHECK/EXPOSE/.dockerignore, single-stage image with a build step. It reports line numbers and exits non-zero on errors, so it also works in CI.

The SKILL.md workflow: analyze the original, classify the app, adapt one of five reviewed templates (Node, Python, Go on distroless, Java on Temurin JRE, Rust on distroless cc; all multi-stage, non-root with fixed UID 10001, BuildKit cache mounts), write a .dockerignore, re-run the analyzer until it reports 0 errors, then show a before/after table with an honest size estimate (measured with docker image ls when Docker is available).

What's in the zip

SKILL.md, README.md, scripts/analyze.py, assets/ (5 Dockerfile templates + dockerignore), examples/ (a 0/100 Dockerfile, its 100/100 rewrite, both analyzer reports). Nothing in the zip executes system commands, deletes files or changes permissions; the analyzer is a pure text parser.

Why it's free

This is one of five skills built the same way (each ships a script the agent must run). The other four - OWASP security review with a hotspot scanner, Playwright E2E generator, hardened GitHub Actions with a linter and SHA pinner, PR/changelog writer from the real git range - are on my Gumroad profile. Try this one first.

Known limitations

The analyzer is static: it cannot tell whether native modules are needed at runtime or measure image size without Docker. Distroless/scratch bases get a warning instead of an error for missing HEALTHCHECK (no shell); use an orchestrator probe.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Dockerfile Optimizer — analyzer + hardened templates skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How exactly does the Dockerfile Optimizer reduce my image size and build times?

This skill analyzes your existing Dockerfiles and refactors them into multi-stage builds, implementing layer caching and security hardening to reduce image sizes and speed up CI/CD pipelines.

### Which programming languages and frameworks are currently supported for optimization?

The skill is pre-configured with optimized templates for Node.js, Python, Go, Java, and Rust, ensuring language-specific best practices for each environment.

### Does the optimizer handle security concerns like root user privileges and .dockerignore files?

Yes, the skill automatically generates comprehensive .dockerignore files and configures non-root users and distroless bases to minimize your attack surface and prevent secret leakage.

### What is included in the purchase of this skill?

You will receive the full AI agent skill package including the 12-point Dockerfile analyzer and all language-specific optimization templates for use within your AI workspace.

### How do I implement the optimized Dockerfiles into my existing workflow?

Simply provide your current Dockerfile or repository structure to the agent, and it will output a refactored version along with a summary of the specific optimizations applied.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
