dockerfile-hardening
Skill0 starsChanged 5 months agoMITView on GitHub
Harden a Dockerfile / container image against common misconfigurations. Trigger when the user says "harden this Dockerfile", "is my container secure", "review my Docker image", or when adding/editing a Dockerfile or container build before shipping.
- Reads credentials
- Deletes or force-pushes
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- kaandgnsh/Claude-Bluetheir own version, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- kaandgnsh/Claude-Blue★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository8 other files it gives its agents.
- ci-security-gateSkill
- dependency-auditSkill
- env-hygieneSkill
- sbom-generationSkill
- secret-rotationSkill
- secscanSkill
- secure-code-reviewSkill
- threat-modelSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
After a base-image bump or when an image scan (Trivy/Grype) flags issues.
- Distinctive: line 18
Read the Dockerfile and note the base image, what runs as root, how secrets are handled, and the layer structure.
- Distinctive: line 22
Verify the image still builds and runs after hardening.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to use
- Writing or reviewing a
Dockerfile,Containerfile, or container build before it goes to a registry or production. - The user asks "is this image secure?" or wants a before/after hardening pass.
- After a base-image bump or when an image scan (Trivy/Grype) flags issues.
Process
- Read the Dockerfile and note the base image, what runs as root, how secrets are handled, and the layer structure.
- Apply the checklist below, top to bottom.
- Produce a before/after Dockerfile so the change is reviewable.
- Recommend a scan to confirm:
trivy image <tag>(orgrype <tag>) andhadolint Dockerfilefor lint. - Verify the image still builds and runs after hardening.
Checklist
- Non-root user — create and
USER appuser; don't run as root. Use a numeric UID for k8srunAsNonRoot. - Pinned base image by digest —
FROM python:3.12-slim@sha256:..., not:latest. Prefer minimal bases (slim, distroless, alpine) to shrink attack surface. - Multi-stage build — build deps in a builder stage; copy only artifacts into a lean runtime stage. Keeps compilers/secrets out of the final image.
- No secrets in layers — never
COPY .env, neverARG/ENVa secret (it persists in history). Use BuildKit secret mounts:RUN --mount=type=secret,id=token .... .dockerignore— exclude.git,.env, secrets,node_modules, build cruft so they never enter the context.- Minimal layers & cleanup — combine
RUNsteps; clean package caches in the same layer (rm -rf /var/lib/apt/lists/*); no leftover temp files. - Pin package versions — pin apt/pip/npm versions for reproducibility; copy lockfiles and install from them.
- Drop capabilities & no new privileges — document running with
--cap-drop=ALL(add back only what's needed),--security-opt=no-new-privileges, and a read-only root filesystem where possible. - HEALTHCHECK — add a
HEALTHCHECKso orchestrators detect a broken container. - No unnecessary tooling — don't ship curl/wget/compilers/shells you don't need at runtime (distroless helps).
How to fix — before/after sketch
Before:
FROM python:latest
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]After:
FROM python:3.12-slim@sha256:<digest> AS build
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-slim@sha256:<digest>
RUN useradd -m -u 10001 appuser
WORKDIR /app
COPY --from=build /install /usr/local
COPY --chown=appuser:appuser . .
USER appuser
HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
CMD ["python", "app.py"]Pair with a .dockerignore (.git, .env, **/__pycache__, node_modules) and run at deploy time with --cap-drop=ALL --security-opt=no-new-privileges --read-only.
Report back
Give a short list of what was hardened (non-root, pinned digest, multi-stage, no secrets, .dockerignore, healthcheck, caps), the before/after Dockerfile, and the scan/lint commands to confirm. Flag anything that needs a runtime/orchestrator change (capabilities, read-only FS) the Dockerfile alone can't enforce.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

