# container-image-hardening

container-image-hardening audits Dockerfiles and built images for production safety, then hands back a hardened build. Run it before a container ships.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 235 installs
- Author: securityskills
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/securityskills/skills/tree/HEAD/container-security/docker/container-image-hardening/SKILL.md
- Updated: 2026-08-26
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/container-image-hardening

## What it does

The skill walks a Dockerfile against a fixed checklist. It asks which base image you started from and whether the tag or digest is pinned rather than `latest`, checks that compilers and package managers stayed out of the final stage, confirms a dedicated `USER` with its own UID, and looks for credentials in `ENV` blocks or a copied `.env`. Dependency pinning through lockfiles gets a look too, along with healthchecks and how apt layers were combined.

Scanning relies on tools you already have: `trivy image`, `grype`, `docker scout cves`. The skill sets up a build gate that fails CI when critical CVEs have a fix available, and it flags base image updates through renovate or dependabot. Verification uses `docker history`, `dive` and `docker run --rm <image> id`, where that last command reveals whether the process runs as root. Miss those utilities in your environment and the scan and inspect steps simply won't run.

What comes back: a rewritten Dockerfile, scan results from before and after the changes, and the CI gate config. For runtime the skill writes launch settings — read-only root filesystem, every capability dropped, no new privileges allowed, `tmpfs` mounted where writes are needed.

## Requirements
- Works with: Docker

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add securityskills/skills --skill container-image-hardening -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/container-image-hardening/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/container-image-hardening/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add securityskills/skills --skill container-image-hardening -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/container-image-hardening/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add securityskills/skills --skill container-image-hardening -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/container-image-hardening/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install securityskills/skills container-security/docker/container-image-hardening
```

2. **Manually: put the files in place**
- File: `.github/skills/container-image-hardening/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add securityskills/skills --skill container-image-hardening -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/securityskills/skills --path container-security/docker/container-image-hardening
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/container-image-hardening/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add securityskills/skills --skill container-image-hardening -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/securityskills/skills/tree/HEAD/container-security/docker/container-image-hardening/SKILL.md

## When to use it
- strip build toolchains from the final image stage
- catch secrets baked into image layers
- run the container under a dedicated non-root UID
- fail the pipeline on critical CVEs
- lock the root filesystem to read-only

## Example prompts
- Review my `Dockerfile` and rewrite it against the hardening checklist
- Add a `trivy image --severity HIGH,CRITICAL --exit-code 1` step to CI for this image
- Set up the container to run with `read_only: true` and dropped capabilities

## Similar
- [container-hardening](https://affpapa.org/en/nevibecode/skills/container-hardening.md) — skill · 491 installs
- [Dockerfile and CI taste](https://affpapa.org/en/nevibecode/prompts/dockerfile-and-ci-taste.md) — prompt · ★ 178201 repo stars
- [container-host-checks](https://affpapa.org/en/nevibecode/skills/container-host-checks.md) — skill · ★ 71 repo stars
- [hardening-docker-containers-for-production](https://affpapa.org/en/nevibecode/skills/hardening-docker-containers-for-production.md) — skill · 373 installs
- [analyzing-docker-container-forensics](https://affpapa.org/en/nevibecode/skills/analyzing-docker-container-forensics.md) — skill · 609 installs
- [dockerfile-optimise](https://affpapa.org/en/nevibecode/skills/dockerfile-optimise.md) — skill · 360 installs

From the same set: [securityskills/skills](https://affpapa.org/en/nevibecode/by/securityskills/skills.md) — 21 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
