Docker Container Optimizer skill for Claude and Codex
Brings a container image under a size budget: a trimmed Dockerfile with a comment on each decision, a .dockerignore, the run flags that harden it, and a…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a container image is over its size budget and needs a trimmed Dockerfile, a .dockerignore, hardened run flags, and a layer-by-layer size estimate. Do not use for scaffolding a new multi-stage Dockerfile for a language, security scanning an image, or debugging a running container. Related topics: coding, docker.
What it will ask you for
- Base image (choose one: alpine:3.20, debian:bookworm-slim, ubuntu:24.04, distroless, Keep current)
- Current Dockerfile (longer free text)
- Essential packages (longer free text)
- Files or directories to exclude (longer free text)
- Environment variables (longer free text)
- Desired maximum image size (MB) (number from 10 to 500)
- Build stage count (choose one: 1, 2, 3)
- Current image size (MB) (free text, e.g. "850")
How it works
- Attribute the current size to base image, caches, build tooling, copied files, and layer ordering, with a rough MB per source.
- Rewrite the Dockerfile: pinned minimal base, essential packages with cache cleanup in one RUN, build tooling in an earlier stage, and a comment per decision.
- Write the .dockerignore from the exclusions and the usual offenders, and substitute any package the chosen base lacks.
- List the docker run flags that harden the container and pass the environment variables.
- Estimate size per layer before and after, state whether the budget is met, and name the next trade-off if not.
What you get
A fenced Dockerfile block with comments, a fenced .dockerignore block, a bullet list of docker run flags, and a Size Estimate table with Layer, Before (MB), and After (MB) columns plus a budget verdict line.
What it watches out for
- Cleaning the package cache in a separate RUN, which leaves the cache in the earlier layer and saves nothing.
- Switching to Alpine for an app that needs glibc, which trades image size for a runtime crash or a musl rebuild.
- Hardening with --read-only without a tmpfs for the paths the app writes, so it fails on first start.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.