About container-image-hardening
A skill for reviewing and hardening Dockerfiles and container images for production use. It checks build practices, vulnerabilities, runtime settings, and verification evidence, and produces a hardened Dockerfile and CI gate configuration.
Key features
- 01Review Dockerfile build practices
- 02Check images for vulnerabilities
- 03Harden runtime security settings
- 04Verify layers and non-root execution
- 05Produce scan reports and CI gates
Use cases
- 01Review a Dockerfile before release
- 02Add vulnerability checks to CI
- 03Reduce container runtime privileges
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ securityskills/ skills --skill container-image-hardeningAfter installing, type/container-image-hardeningin Claude Code to confirm it loaded.
Details
From the project READMEContainer Image Hardening
Review and fix Dockerfiles and images for production safety.
Dockerfile Review Checklist
- Base image: official, specific tag or digest, minimal variant (
alpine,distroless,slim); neverlatest - Multi-stage builds: build toolchains (compilers, package managers) excluded from final image
- Non-root user:
USERdirective with a dedicated UID; no sudo in image - No secrets: no
ENVwith credentials, noCOPY .env, no secrets baked into layers (they persist even if deleted later) - Pinned dependencies: lockfiles used (
npm ci,pip install -r requirements.txtwith hashes) - Healthchecks defined;
ENTRYPOINToverCMDfor enforced init - Layer hygiene: combine apt operations and clean lists in one layer;
.dockerignorecovers.git, build artifacts
Scan and Gate
trivy image --severity HIGH,CRITICAL --exit-code 1 <image>
grype <image>
docker scout cves <image>
- Fail CI on critical CVEs with available fixes
- Track base image updates (renovate/dependabot for Dockerfiles)
Runtime Hardening
read_only: true
cap_drop: ["ALL"]
security_opt: ["no-new-privileges:true"]
tmpfs: [/tmp]
- Resource limits set (CPU/memory) to blunt DoS
- Root filesystem read-only; writable paths explicit tmpfs
Verification
docker history <image>— no secret-looking layersdive <image>— image efficiency and wasted space- Run as the image user:
docker run --rm <image> idshows non-root
Output
Hardened Dockerfile, scan report before/after, and CI gate configuration.
Comments
Markdown supported