dockerfile-optimizerlisted
Install: claude install-skill imtiazrayhan/agentscamp-library
Take a Dockerfile that already works and make it smaller, faster to build, and safer to run — without changing what the container actually does. This skill reads the existing Dockerfile and build context, then applies the standard, high-leverage optimizations: multi-stage builds so build tools never ship in the final image, layer ordering that lets the cache hit on unchanged dependencies, a lean and pinned base image, a `.dockerignore`, and a non-root runtime user.
## When to use this skill
- The image is large (hundreds of MB to gigabytes) and you want it smaller.
- Builds are slow because a small source change reinstalls all dependencies (cache never hits).
- A scanner or reviewer flagged the container running as `root`, an unpinned `:latest` base, or secrets in a layer.
- You're preparing an image for production and want it lean and reproducible.
> [!NOTE]
> This is behavior-preserving. The optimized image must run the same command, expose the same ports, and produce the same result. Don't change the app's runtime behavior, upgrade its language version, or swap frameworks — only how the image is built and packaged.
## Instructions
1. **Read the current state.** Read the `Dockerfile`, any `.dockerignore`, and the build context layout. Identify the language/runtime, the build steps, and the final `CMD`/`ENTRYPOINT`. Build once to get a baseline: `docker build -t img:before .` and record the size with `docker images img:before`.
2. **Introduce (or tighten) a multi-stage