container-hardening — Claude Code skill: what it does, how to install
Hardens Docker images and runtime environments with non-root users, read-only filesystems, and Kubernetes security contexts.
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-codeWhat container-hardening does
This skill provides templates and rules to lock down container images and deployment manifests. It outlines Dockerfile patterns using dedicated non-root users with UID 1001, minimal base images like Alpine or distroless, and explicit ownership via --chown.
For execution, it includes hardened docker run flags such as --cap-drop=ALL, --security-opt=no-new-privileges:true, and --read-only. It also covers Kubernetes Pod manifests with strict securityContext configurations and image scanning rules via Trivy.
Applications that require arbitrary writes across the filesystem will fail under these restrictions. You will need to declare explicit writable paths, such as --tmpfs /tmp, before deploying.
What it helps with
- switch Dockerfile builds to an unprivileged user
- drop unnecessary Linux capabilities on container startup
- configure securityContext for Kubernetes pods
- scan container images for high-severity vulnerabilities with Trivy
Example prompts for the agent
- Harden this Dockerfile by creating a non-root user and stripping build tools.
- Generate a Kubernetes pod manifest with read-only root filesystem and dropped capabilities.
- Show a secure docker run command that blocks privilege escalation.
How to install container-hardening
1Skills CLI (Vercel)
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-code2Manually: put the files in place
~/.claude/skills/container-hardening/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/container-hardening/
1Skills CLI (Vercel)
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a codex2Manually: put the files in place
.agents/skills/container-hardening/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a cursor2Manually: put the files in place
.cursor/skills/container-hardening/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install BagelHole/DevOps-Security-Agent-Skills container-hardening2Manually: put the files in place
.github/skills/container-hardening/SKILL.md1Skills CLI (Vercel)
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a gemini-cli2Platform CLI
gemini skills install https://github.com/BagelHole/DevOps-Security-Agent-Skills --path security/hardening/container-hardeningManually: put the files in place
.devin/skills/container-hardening/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about container-hardening
How do I install container-hardening in Claude Code?
Run npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-code in your terminal.
What does container-hardening do?
It guides the assistant in securing Dockerfiles, locking down container runtime options, and applying Kubernetes security contexts.
Which image scanner is featured in the skill templates?
It includes scanning examples using Trivy configured for HIGH and CRITICAL vulnerability severities.
Source text
SKILL.md · MIT
---
name: container-hardening
description: Secure Docker images and container runtime configurations. Implement non-root users, read-only filesystems, and security contexts. Use when building secure container images or hardening container deployments.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# Container Hardening
Secure container images and runtime configurations.
## When to Use This Skill
Use this skill when:
- Building secure container images
- Hardening container deployments
- Meeting container security requirements
- Implementing defense in depth
## Dockerfile Security
```dockerfile
# Use minimal base image
FROM alpine:3.18
# Don't run as root
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
# Copy with specific ownership
COPY --chown=appuser:appgroup . /app
# Remove unnecessary packages
RUN apk del --purge build-dependencies && \
rm -rf /var/cache/apk/*
# Use non-root user
USER appuser
# Read-only filesystem support
WORKDIR /app
```
## Runtime Security
```bash
# Run with security options
docker run -d \
--read-only \
--tmpfs /tmp \
--security-opt=no-new-privileges:true \
--cap-drop=ALL \
--cap-add=NET_BIND_SERVICE \
--user 1001:1001 \
myapp:latest
```
## Kubernetes Security Context
```yaml
apiVersion: v1
kind: Pod
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1001
fsGroup: 1001
containers:
- name: app
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
```
## Image Scanning
```bash
# Scan with Trivy
trivy image --severity HIGH,CRITICAL myapp:latest
# Use distroless images
FROM gcr.io/distroless/static-debian11
```
## Best Practices
- Use minimal base images
- Run as non-root user
- Enable read-only filesystem
- Drop all capabilities
- Scan images regularly
- Sign and verify images
- Use secrets management
## Related Skills
- [container-scanning](../../scanning/container-scanning/) - Vulnerability scanning
- [kubernetes-hardening](../kubernetes-hardening/) - K8s security
© devops-skills · MIT · BagelHole/DevOps-Security-Agent-Skills