- Home
- Skills
- DevOps & Cloud
- Dockerfile Doctor: harden, shrink & speed up builds
Dockerfile Doctor: harden, shrink & speed up builds
Audits any Dockerfile with 21 checks (root user, secrets in ENV/ARG, unpinned images, cache-busting COPY order, missing multi-stage) via a tested script, then writes a corrected, production-ready Dockerfile.
Free
Dockerfile Doctor: harden, shrink & speed up builds
Example session with this skill installed
Audit my Dockerfile. Every one-line code change triggers a full pip reinstall, the image is over 1 GB, and security flagged it. Fix it.
FROM python:3.9
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y gcc libpq-dev
RUN pip install -r requirements.txt
ENV DB_PASSWORD=changeme
EXPOSE 8000
CMD python app.py
- Read your context and instructions
- Compiled the dockerfile doctor
Summary
Ran scripts/dockerfile_audit.py:
2 HIGH, 4 MEDIUM, 3 LOW, 1 INFO. The slow builds come from COPY . . before pip install; the size from shipping gcc in a single stage; the security flags from running as root and a password baked into the image.
Findings (real script output)
| Sev | Rule | Line | Problem |
|---|---|---|---|
| HIGH | DF003 | 1 | Final image runs as root |
| HIGH | DF014 | 6 | ENV DB_PASSWORD is stored in image history/metadata |
| MEDIUM | DF018 | 1 | Single-stage build ships build tooling (gcc) to runtime |
| MEDIUM | DF004 | 4 | apt install without --no-install-recommends |
| MEDIUM | DF005 | 4 | apt lists not removed in the same layer |
| MEDIUM | DF017 | 5 | Dependencies install after COPY . .: every code change busts the cache |
| LOW | DF002 | 1 | Base pinned by tag, not digest |
| LOW | DF008 | 5 | pip cache kept in image |
| LOW | DF020 | 8 | Shell-form CMD: app won't receive SIGTERM |
Corrected Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.9.20-slim AS builder
ENV PIP_NO_CACHE_DIR=1
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc libpq-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip wheel --wheel-dir /wheels -r requirements.txt
FROM python:3.9.20-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends libpq5 \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --create-home --uid 10001 app
COPY --from=builder /wheels /wheels
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
COPY --chown=app:app . .
USER app
EXPOSE 8000
CMD ["python", "app.py"]
What changed and why
- Manifest copied before source: code edits no longer reinstall dependencies.
- Multi-stage: gcc and headers stay in
builder; runtime keeps onlylibpq5. - Non-root
USER app: clears DF003. DB_PASSWORDremoved from the image: pass it at runtime (docker run -e/ your orchestrator's secrets).- Exec-form CMD: clean shutdowns on SIGTERM.
Behaviour changes to check
DB_PASSWORDmust now be supplied at runtime.- The app runs as UID 10001: make sure it doesn't write outside
/appor/tmp.
Next steps
- Add a
.dockerignore(.git,__pycache__,.env*,.venv). - Rebuild and re-run the audit: no HIGH findings should remain.
Connects securely to your tools. The creator never sees your data.
About this skill
Docker builds often result in bloated images, slow cache invalidation, and critical security holes like running as root. This skill audits your container configuration to produce hardened, multi-stage Dockerfiles optimized for speed and production safety.
What it does
- Security hardening identifies root user usage, leaked secrets in layers, and unpinned base images.
- Image optimization implements multi-stage builds and slim base images to reduce total footprint.
- Cache engineering restructures commands to ensure dependency layers only rebuild when manifests change.
- Context analysis reviews
.dockerignoreand dependency files to prevent accidental sensitive data exposure. - Automated auditing uses specialized scripts to flag specific rule violations from DF001 to DF021.
How it works
- Context gathering analyzes the Dockerfile, lockfiles, and deployment manifests to understand the runtime requirements.
- Audit execution runs a diagnostic script to generate a checklist of severity-rated violations.
- Manual verification checks for non-automatable issues like missing
.dockerignorepatterns or hardcoded credentials. - Code generation rewrites the Dockerfile using multi-stage patterns and non-root users while preserving original runtime behavior.
Frameworks & tools
This skill works with standard Docker, BuildKit, and language-specific package managers including npm, pip, go modules, and maven. It supports Debian, Alpine, and Distroless base image patterns.
Why this beats prompting it yourself
Generic prompts often miss the specific ordering required for layer caching or fail to provide the non-root user setup needed for production. This skill uses a structured audit script and a library of proven templates to ensure no security rules are skipped.
Use cases
- Shrink massive production images that are slowing down CI/CD pipelines.
- Remove root user privileges to meet SOC2 or enterprise security requirements.
- Fix broken layer caching that forces full re-installs on every small code change.
- Migrate legacy single-stage Dockerfiles to modern multi-stage architectures.
Known limitations
The skill cannot guarantee compatibility when switching C libraries, such as moving from Debian to Alpine. It requires access to dependency manifests for optimal cache layering.
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 buying a skill.
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
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 14 days ago
- Free with an Agensi account
- Software
Python 3.8+
- Optional
Docker (to verify image size)
Permissions
Shell runs the bundled audit script (python, standard library only). Read: your Dockerfile, .dockerignore and dependency manifests. Write: the corrected Dockerfile/.dockerignore, only after you approve. The scripts make no network calls; only the optional `docker build` verification step pulls base images.
What's inside
Frequently Asked Questions
New in DevOps & Cloud
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for DevOps & Cloud.