dockerfile-hardener
Skill0 starsChanged 6 months agoMITView on GitHub
Hardens and optimizes Dockerfiles for security and size — non-root user, pinned base images, multi-stage builds, minimal layers, no leaked secrets, and a proper healthcheck. Use when the user shares a Dockerfile, asks to harden, secure, or shrink a container image, reduce attack surface, or follow Docker best practices.
- Reads credentials
- Deletes or force-pushes
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- 00PrabalK00/claude-skillstheir own version, first seen Mar 16, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- 00PrabalK00/claude-skills★ 1same 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 repository11 other files it gives its agents.
- a11y-auditorSkill
- api-design-reviewerSkill
- changelog-writerSkill
- conventional-commit-writerSkill
- env-secrets-auditorSkill
- error-message-explainerSkill
- pr-description-writerSkill
- readme-generatorSkill
- regex-builderSkill
- sql-query-optimizerSkill
- test-writerSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 83
High: no multi-stage (bloated image with build tools), no .dockerignore.
- Very specific: line 153
Apps that must bind to port <1024: prefer a high port + reverse proxy.
≈ “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
Dockerfile Hardener
Review a Dockerfile and return a hardened version that is smaller, more secure, and reproducible. Report each change with the reason and severity.
Workflow
- [ ] 1. Read the Dockerfile and identify the language/runtime
- [ ] 2. Run the hardening checklist
- [ ] 3. Report findings (severity + reason) and the rewritten Dockerfile
- [ ] 4. Suggest a .dockerignore and a quick scan commandHardening checklist
Security (highest priority)
- Run as non-root. Containers default to root. Create and switch to an unprivileged user.
RUN addgroup --system app && adduser --system --ingroup app app USER app - Pin the base image to a digest (or at least a specific minor tag), never
:latest.FROM node:22.11-bookworm-slim@sha256:<digest> - Never bake secrets into layers. Anything in
ENV,ARG, or aCOPY'd.envis recoverable from image history. Use BuildKit secrets or runtime env vars.RUN --mount=type=secret,id=npm_token \ NPM_TOKEN=$(cat /run/secrets/npm_token) npm ci - Use minimal base images —
-slim,alpine,distroless, orscratch— to shrink the attack surface. Fewer packages, fewer CVEs. - Drop privileges and capabilities at runtime (document for the user):
--read-only,--cap-drop=ALL,--security-opt=no-new-privileges. - Don't install unnecessary tools (curl, build toolchains) in the final image; keep them in a build stage only.
Image size & build speed
- Multi-stage build: compile/install in a builder stage, copy only the artifacts into a tiny runtime stage.
- Order layers from least to most frequently changing. Copy dependency manifests and
install before copying source, so dependency layers stay cached.
COPY package.json package-lock.json ./ RUN npm ci --omit=dev COPY . . - Combine related
RUNsteps and clean package caches in the same layer (a separate cleanup layer doesn't reclaim space).RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \ && rm -rf /var/lib/apt/lists/* - Add a
.dockerignoreso.git,node_modules, secrets, and test files never enter the build context.
Correctness & operability
- Use exec-form
CMD/ENTRYPOINT(["node","server.js"]) so signals reach the process and the container shuts down cleanly; add an init (--initor tini) if you fork children. - Add a
HEALTHCHECKso orchestrators know when the app is actually ready. - Set
WORKDIRexplicitly; don't rely on/. - Pin dependency installs to lockfiles (
npm ci,pip install -r requirements.txtwith hashes,go mod download).
Severity guide
- Critical: runs as root, baked-in secret,
:latestbase, no dependency pinning. - High: no multi-stage (bloated image with build tools), no
.dockerignore. - Medium: poor layer caching, shell-form CMD, missing healthcheck.
- Low: style, comments, ordering polish.
Example: before → after (Node)
Before:
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install
ENV API_KEY=sk_live_abc123
CMD npm startAfter:
# syntax=docker/dockerfile:1
FROM node:22.11-bookworm-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build && npm prune --omit=dev
FROM node:22.11-bookworm-slim AS runtime
ENV NODE_ENV=production
WORKDIR /app
RUN addgroup --system app && adduser --system --ingroup app app
COPY --from=build --chown=app:app /app/node_modules ./node_modules
COPY --from=build --chown=app:app /app/dist ./dist
COPY --from=build --chown=app:app /app/package.json ./
USER app
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD node -e "fetch('http://127.0.0.1:3000/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
ENTRYPOINT ["node", "dist/server.js"]Changes: pinned base, multi-stage to drop dev deps and build tools, non-root user, removed the
baked-in secret (pass API_KEY at runtime), cache-friendly layer order, exec-form entrypoint,
and a healthcheck.
Recommended .dockerignore
.git
node_modules
npm-debug.log
Dockerfile
.dockerignore
.env
*.md
dist
coverage
.vscodeVerify
Suggest scanning the built image and checking the user:
docker scout cves <image> # or: trivy image <image>
docker run --rm <image> whoami # should NOT print "root"
docker history <image> # confirm no secrets in layersCommon edge cases
- Apps that must bind to port <1024: prefer a high port + reverse proxy; only grant
CAP_NET_BIND_SERVICEif truly required. - Compiled languages (Go/Rust): build static binaries and use
FROM scratchorgcr.io/distroless/staticfor a near-zero-CVE image. - Native build dependencies: install them in the builder stage only.
- Files the app writes at runtime: mount a volume or
tmpfs; keep the root filesystem read-only where possible.
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.

