dockerfile-hardening
Skill0 starsChanged 12 days agoMITView on GitHub
Review and harden Dockerfiles and container build practice — minimal pinned base images, multi-stage builds, non-root USER, no secrets in layers (BuildKit secret mounts), least packages, HEALTHCHECK, read-only filesystems — with hadolint and image scanners. Use when writing or reviewing a Dockerfile, or when image scans show secrets, root users or bloated images.
- Pipes a download into a shell
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Hayatelin/devsecops-skillstheir own version, first seen Jun 27, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Hayatelin/devsecops-skills★ 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 repository273 other files it gives its agents.
- ad-attack-path-analysisSkill
- adcs-security-reviewSkill
- ad-privileged-access-reviewSkill
- dcsync-detectionSkill
- gpo-security-reviewSkill
- kerberos-attack-detectionSkill
- agent-tool-permission-reviewSkill
- ai-incident-responseSkill
- llm-gateway-controlsSkill
- llm-security-evaluationSkill
- mcp-server-security-reviewSkill
- model-artifact-securitySkill
- prompt-injection-reviewSkill
- rag-security-reviewSkill
- api-abuse-detectionSkill
- api-authorization-testingSkill
- api-inventorySkill
- api-schema-securitySkill
- dast-baselineSkill
- sast-triageSkill
- sca-dependency-riskSkill
- secure-code-reviewSkill
- security-requirementsSkill
- threat-modelingSkill
- asset-criticality-tieringSkill
- asset-inventory-reconciliationSkill
- external-attack-surface-reviewSkill
- shadow-it-discoverySkill
- aws-credential-compromiseSkill
- aws-iam-reviewSkill
- aws-org-guardrailsSkill
- cloudtrail-investigationSkill
- guardduty-triageSkill
- s3-exposure-reviewSkill
- azure-activity-investigationSkill
- azure-rbac-reviewSkill
- conditional-access-reviewSkill
- entra-audit-investigationSkill
- entra-signin-investigationSkill
- backup-assuranceSkill
- critical-service-mappingSkill
- ransomware-recoverySkill
- recovery-exerciseSkill
- cloud-exposure-reviewSkill
- cloud-incident-responseSkill
- cloud-logging-baselineSkill
- cloud-posture-assessmentSkill
- audit-evidence-packageSkill
- continuous-control-monitoringSkill
- control-mappingSkill
- control-testing-samplingSkill
- container-incidentSkill
- image-scanningSkill
- runtime-detection-falcoSkill
- db-audit-loggingSkill
- db-exfiltration-investigationSkill
- db-hardeningSkill
- db-privilege-reviewSkill
- data-classificationSkill
- data-discoverySkill
- The first 60 shown.
The file
Files
Dockerfile Hardening
Example
# syntax=docker/dockerfile:1
FROM golang:1.23@sha256:<digest> AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN --mount=type=secret,id=netrc,target=/root/.netrc CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/app ./cmd/app
FROM gcr.io/distroless/static-debian12:nonroot@sha256:<digest>
COPY --from=build /out/app /app
USER nonroot:nonroot
EXPOSE 8080
ENTRYPOINT ["/app"]Build with the secret: docker build --secret id=netrc,src=$HOME/.netrc -t app . — the secret never lands in a layer.
Checklist
- Base image minimal and pinned by digest; from an approved registry.
- Multi-stage: compilers/package managers not in the final image.
USERnon-root (numeric UID helps withrunAsNonRootpolicies).- No secrets in
ENV,ARG,COPYed files, or earlier layers (deleting in a later layer doesn't remove them) — check withdocker history --no-truncandtrivy image --scanners secret. COPYspecific paths (with.dockerignoreexcluding.git,.env, keys) rather thanCOPY . .into the final stage.- Package installs pinned/minimal with
--no-install-recommends, caches cleaned in the same layer. - No
curl | shfrom the internet without checksum verification. HEALTHCHECK(or orchestrator probes) defined.- Runtime settings documented: read-only root FS, drop all capabilities, no privilege escalation (enforced in Kubernetes securityContext —
k8s-admission-control).
Lint
hadolint Dockerfile (rules like DL3006 tag the image, DL3008 pin apt versions, DL3002 last USER should not be root); trivy config Dockerfile; checkov -f Dockerfile.
Related skills
image-scanning, k8s-admission-control, secret-scanning, iac-scanning
References
- Docker build best practices: https://docs.docker.com/build/building/best-practices/
- BuildKit secret mounts: https://docs.docker.com/build/building/secrets/
- hadolint: https://github.com/hadolint/hadolint
- CIS Docker Benchmark: https://www.cisecurity.org/benchmark/docker
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.

