ProSkillsLibraryFreePassScan
DevOps & Cloud

DevOps & Cloud · agent skill

Dockerfile Doctor

Smaller, faster, safer images.

What it does

Loads when it is needed

Your agent loads it when the user writes or fixes a Dockerfile. It carries 5 rules and reads a profile.md with your details before it starts, so the output matches your brand and project.

Same prompt, with and without

Slim down a FastAPI image

Prompt · Our API image is 1.4 GB and every rebuild takes about 6 minutes even for a one-line change. Can you fix this Dockerfile?

1 FROM python:3.12
2 WORKDIR /app
3 COPY . .
4 RUN apt-get update && apt-get install -y build-essential libpq-dev
5 RUN pip install -r requirements.txt
6 ENV DATABASE_URL=postgresql://app:hunter2-prod@db.internal:5432/app
7 EXPOSE 8000
8 CMD uvicorn app.main:app --host 0.0.0.0 --port 8000
requirements.txt pins versions (psycopg2 builds from source). No .dockerignore in the repo.
Built in GitHub Actions, deployed to ECS Fargate (linux/amd64) behind an ALB.

Profile used: AWS, ECS Fargate, GitHub Actions; dev, staging, production

Without the skill
Main problems: full python:3.12 base, COPY . . before installing deps (every code change reinstalls everything, which is your 6 minutes), build tools shipped in the final image, no .dockerignore, and root user. Urgent: line 6 bakes a prod database password into the image. Anyone who can pull the image can read it. Rotate that password, remove the ENV line, and inject it at runtime through ECS task definition secrets (Secrets Manager or SSM). FROM python:3.12-slim AS build RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip wheel --no-cache-dir -r requirements.txt -w /wheels FROM python:3.12-slim RUN apt-get update && apt-get install -y --no-install-recommends libpq5 \ && rm -rf /var/lib/apt/lists/* && useradd -r -u 10001 app WORKDIR /app COPY requirements.txt . RUN --mount=type=bind,from=build,source=/wheels,target=/wheels \ pip install --no-cache-dir --no-index --find-links=/wheels -r requirements.txt COPY --chown=app app ./app USER app EXPOSE 8000 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] .dockerignore: .git, .env*, __pycache__, *.pyc, .venv, tests, node_modules. In GitHub Actions use docker/build-push-action with cache-from/cache-to type=gha so layers persist between runs. Now a one-line code change only rebuilds the last COPY layer.
With the skill
Dockerfile audit: api Measured: not measured (no Docker daemon here); run the Verify commands and compare. Findings 1 HIGH L1 python:3.12 floats: pin python:3.12.7-slim-bookworm plus digest (docker buildx imagetools inspect), bumped by Renovate. 2 HIGH L6 DATABASE_URL with a password is baked in and shows in docker history. Inject from Secrets Manager via the task definition, and rotate it: it is in git. 3 HIGH L3 COPY . . before pip install: every edit reinstalls all dependencies. 4 HIGH no USER: runs as root. 5 MED L4 compilers ship in the final image: no multi-stage. 6 MED L8 shell-form CMD: SIGTERM never reaches uvicorn, so ECS waits out the stop timeout. 7 MED unhashed install: pip-compile --generate-hashes, then --require-hashes. 8 LOW no .dockerignore: .git and .env enter the context. No HEALTHCHECK: ECS uses the task definition and ALB checks. # syntax=docker/dockerfile:1.7 FROM python:3.12.7-slim-bookworm AS build RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev && rm -rf /var/lib/apt/lists/* RUN python -m venv /opt/venv ENV PATH=/opt/venv/bin:$PATH COPY requirements.txt . RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt FROM python:3.12.7-slim-bookworm ENV PYTHONUNBUFFERED=1 PATH=/opt/venv/bin:$PATH RUN apt-get update && apt-get install -y --no-install-recommends libpq5 && rm -rf /var/lib/apt/lists/* && useradd --uid 10001 app COPY --from=build /opt/venv /opt/venv WORKDIR /app COPY --chown=app:app app ./app USER app EXPOSE 8000 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] .dockerignore: .git, .env*, __pycache__, .venv, tests, .github Verify: build twice (edit one file between), docker image ls api, time docker stop.

Both answers from the same model (Claude sonnet), 2026-10-16. The one without the skill was written in a separate session that never saw it. Shortened where marked with …

SKILL.md

First 40 lines

---
name: dockerfile-doctor
description: "Use when the user says 'review my Dockerfile', 'my docker image is huge', 'docker build is slow', 'optimize this Dockerfile', 'make this image production ready', 'add a multi-stage build', 'run as non-root', or 'why is the cache busting'. Audits a Dockerfile and .dockerignore, rewrites them with multi-stage builds, lockfile-first layer order, pinned bases, a non-root user, no secrets in layers, a healthcheck and correct signal handling, and reports image size and build time before and after. Reads profile.md for cloud, runtime, CI and environments; per-language templates and findings checklist in templates.md."
---

# Dockerfile Doctor

Audit a Dockerfile the way a platform engineer would: find what makes the image big, slow to build, insecure or hard to stop, fix it, and prove the improvement with numbers. Do not rewrite for style; every change must buy size, build time, safety or reproducibility.

## Before you start

Read `profile.md` in this folder:

| profile.md line | Use |
|---|---|
| **Cloud** | Registry and platform quirks (ECR, Artifact Registry, ACR, Fly, Render) and the CPU architecture to build for. |
| **Runtime** | Kubernetes: add probes in the manifest, not only `HEALTHCHECK`, and set `runAsNonRoot`. Containers (ECS / Cloud Run): the platform health check replaces `HEALTHCHECK`; listen on `$PORT` for Cloud Run. Serverless: image must match the Lambda base and handler contract. VMs: keep `HEALTHCHECK`. |
| **CI** | Where the build runs; use its cache backend (`type=gha`, registry cache) in the build command you suggest. |
| **Environments** | Which environments build the image; one image per commit, configuration injected at run time, never baked per environment. |

If a line says "not set", ask once, write it into profile.md, continue. Open `templates.md` for the language template and the findings checklist.

## Workflow

1. **Read everything the build reads.** The Dockerfile, `.dockerignore`, the lockfile and manifest, any compose file or CI build step. Identify language, framework, entrypoint, port and what the app needs at run time versus build time.
2. **Measure the baseline.** If Docker is available and the user agrees to a local build: `docker build -t app:before .` twice (cold with `--no-cache`, then warm after touching one source file), `docker image ls app:before`, `docker history app:before`. Record size and seconds. If you cannot build, say "not measured" and estimate nothing.
3. **Audit** against the findings checklist in `templates.md`. Label each finding high, medium or low (table below).
4. **Rewrite** with the smallest set of changes that fixes the highs and mediums. Keep the app's existing behaviour: same port, same command, same env var names.
5. **Add or fix `.dockerignore`** before touching layers; a missing one is the most common cause of cache busting and leaked files.
6. **Rebuild and compare.** Same two builds, same machine. Report size and times as before, after, delta. Run the container and confirm it starts, answers its health check and stops within seconds on `docker stop`.
7. **Hand over** the diff and the commands. Do not push, tag or publish an image, and do not touch a registry or cluster without asking.

## Severity

| Severity | Examples |
|---|---|
| High | Secret or token in a layer or `ARG`; runs as root with no reason; `latest` or unpinned base in production; `curl` piped to a shell during build; whole repo copied before dependency install on every change |
| Medium | No multi-stage (compilers and dev dependencies shipped); shell-form `CMD` so signals are lost; no `.dockerignore`; no healthcheck; non-reproducible install (`npm install`, unpinned `pip`) |
| Low | Many small `RUN` layers; missing `--no-install-recommends`; apt/apk caches left behind; no `LABEL`s |

Install

One command, in your project

It detects your agent; add --agent all for every agent.

npx proskills-cli add dockerfile-doctor

Or copy the skill folder (the one holding SKILL.md) into the directory your agent reads, then restart it or start a new session.

AgentThis projectEvery project
Claude Code.claude/skills/~/.claude/skills/
Cursor.agents/skills/ (or .cursor/skills/)~/.cursor/skills/
Codex.agents/skills/~/.agents/skills/
Gemini CLI.agents/skills/ (or .gemini/skills/)~/.gemini/skills/

Changelog

What changed

  • v1.0.0 · 2026-10-16
    • First versioned release: Smaller, faster, safer images.
    • Scanned 100/100 before release.

Keep it current with npx proskills-cli update; your profile.md is never touched.

Same collection

More from DevOps & Cloud

The scan checks spec compliance, token cost, clarity and security patterns. A clean scan is not a guarantee: static scanners can be evaded. Scan any skill yourself.