- Home
- Skills
- DevOps & Cloud
- Container Image Doctor: Smaller, Faster, Safer Builds
Works with the AI Agents you already use
Container Image Doctor: Smaller, Faster, Safer Builds
Reviews a Dockerfile against nine common problems, writes an improved version with a diff and a reason for every change, and compares image sizes you measured before and after.
$5
Container Image Doctor: Smaller, Faster, Safer Builds
Example session with this skill installed
Review this Dockerfile and make the image smaller without changing how the app runs.
- Read your context and instructions
- Compiled the container image doctor
I checked the bundled demo: an invented Node.js app's Dockerfile and .dockerignore.
Step 1: check the Dockerfile as written
Dockerfile check: 1 stage(s), 9 instruction(s)
check result
------------- -----------
pin warn
multi-stage note
cache-order warn
copy-early ok
package-cache warn
user warn
healthcheck note
dockerignore warn
arg-env warn
7 warning(s), 2 note(s)
- .dockerignore [warn] dockerignore .dockerignore does not exclude .git and the whole context is copied
- .dockerignore [warn] dockerignore .dockerignore does not exclude .env and the whole context is copied
- line 1 [warn] pin base image has no tag or digest, so it pulls whatever the latest tag is
- line 1 [warn] user no USER in the final image, so it runs as the base image's user, which is root unless the base image sets another
- line 1 [note] healthcheck no HEALTHCHECK in the Dockerfile (the base image may set one); add one unless your platform runs its own health checks
- line 2 [note] multi-stage one stage compiles or builds and also ships; a build stage plus a small final stage keeps compilers and sources out of the image
- line 2 [warn] package-cache apt-get or apt install without removing /var/lib/apt/lists in the same RUN
- line 4 [warn] cache-order the whole build context is copied before the dependency install, so any file change reinstalls every dependency; copy the manifest and lock file first, install, then copy the rest
- line 7 [warn] arg-env ENV name says it holds a credential; build arguments and environment values stay readable in the image history or config, so pass it as a build secret or at run time
For the demo I take these as your answers: the app runs on Node.js 22 and a slim image is fine, it runs under a plain container runtime, and at run time it reads package.json, node_modules and the built dist/, where dist/healthcheck.js exits 0 when the app answers.
Step 2: improved Dockerfile, as a diff
--- Dockerfile.before
+++ Dockerfile.after
@@ -1,9 +1,25 @@
-FROM node
-RUN apt-get update && apt-get install -y python3 make g++
+# syntax=docker/dockerfile:1
+
+# Build stage: compilers and dev dependencies stay here.
+FROM node:22-bookworm-slim AS build
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends python3 make g++ \
+ && rm -r /var/lib/apt/lists/*
WORKDIR /app
-COPY . .
+COPY package.json package-lock.json ./
RUN npm ci
-RUN npm run build
-ENV SESSION_SECRET=... (value not shown)
+COPY . .
+RUN npm run build && npm prune --omit=dev
+
+# Final stage: only what the app reads at run time (package.json, node_modules, dist).
+# Assumed for the demo: Node.js 22 and a slim image are fine, and dist/healthcheck.js exits 0 when the app answers.
+FROM node:22-bookworm-slim
+ENV NODE_ENV=production
+WORKDIR /app
+COPY --from=build --chown=node:node /app/package.json ./package.json
+COPY --from=build --chown=node:node /app/node_modules ./node_modules
+COPY --from=build --chown=node:node /app/dist ./dist
+USER node
EXPOSE 3000
+HEALTHCHECK --interval=30s --timeout=3s CMD ["node", "dist/healthcheck.js"]
CMD ["node", "dist/server.js"]
--- dockerignore.before
+++ dockerignore.after
@@ -1,2 +1,5 @@
+.git
+.env
node_modules
+dist
npm-debug.log
| change | check | reason |
|---|---|---|
node → node:22-bookworm-slim | pin | A tag you chose instead of whatever latest points to today. |
| build stage + slim final stage | multi-stage | Compilers and dev dependencies stay in the build stage and never ship. |
copy package.json and the lock file, npm ci, then copy the rest | cache-order | A code change no longer reinstalls every dependency. |
--no-install-recommends and rm -r /var/lib/apt/lists/* in the same RUN | package-cache | The apt lists do not stay in a layer. |
| credential-named ENV removed | arg-env | Values set with ENV stay readable in the image config; pass it at run time or as a build secret. |
USER node | user | The app no longer runs as root. |
HEALTHCHECK | healthcheck | The runtime can tell when the app stops answering. |
.git, .env and dist in .dockerignore | dockerignore | History and local secrets stay out of the build context. |
Step 3: check the rewrite
Dockerfile check: 2 stage(s), 17 instruction(s)
check result
------------- -----------
pin ok
multi-stage ok
cache-order ok
copy-early ok
package-cache ok
user ok
healthcheck ok
dockerignore ok
arg-env ok
0 warning(s), 0 note(s)
Size
Nothing was built, so no size gain is claimed. To measure it, build both versions on the same machine and save docker image inspect (or docker history --format json) for each, then run compare_history.py on the two files. It prints the bytes before and after and the change in percent.
Want me to review your own Dockerfile?
Connects securely to your tools. The creator never sees your data.
About this skill
Use when a Dockerfile works but the image is large, every rebuild reinstalls dependencies, the container runs as root, or you want a second pair of eyes before you ship. A standard-library Python script checks the Dockerfile and its .dockerignore for nine problems: an unpinned base image, a single stage that also compiles, a copy order that defeats the build cache, the whole context copied first, package caches left in layers, no non-root user, no health check, missing ignore entries, and credentials in ARG or ENV (shown as type and length, never the value). The skill then writes an improved Dockerfile, shows the diff and gives one reason per change, and checks the rewrite again. A second script compares image sizes from inspect or history JSON you saved before and after; no size gain is claimed until you have measured it. The checks read the Dockerfile text only: they do not build, pull or scan images. Do not use when you need a Compose or Kubernetes setup, a vulnerability scan of an image, or a Dockerfile written from scratch for a project that has none.
Example prompts
- "Review this Dockerfile and make the image smaller without changing how the app runs."
- "Every build reinstalls all my npm packages. What's wrong with my Dockerfile?"
- "Here is docker image inspect output before and after your changes. How much smaller did it get?"
Requires
Python 3.9+ (standard library only) and bash or zsh for the commands with a separator line. Measuring sizes needs Docker Engine or a compatible container engine on your machine; the review itself does not. On claude.ai the demo runs with code execution enabled.
Compatibility
Written for SKILL.md-compatible agents, for example Claude Code, Claude.ai skills, Codex CLI, Cursor or Gemini CLI. Each documents the SKILL.md format; not every agent was tested. The seller suggests Claude Sonnet 4.5 or later.
Limits
The nine checks, the command lists and the credential-name words are the skill's own heuristics. The checks read the Dockerfile text and cannot see what the base image sets (its user, health check or packages). A credential under an innocent name is missed, and this is not a security audit or vulnerability scan. Only .git, .env and node_modules are checked in the ignore file. The improved Dockerfile is a proposal to build and test.
Independence
Not affiliated with or endorsed by Docker, Inc., Anthropic, OpenAI, Anysphere (Cursor) or Google. Product names are used only to describe compatibility and what the skill reviews. Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 5 days ago
Requires