
Container Hardening
- 118 installs
- 44 repo stars
- Updated May 22, 2026
- bagelhole/devops-security-agent-skills
Container Hardening is a Claude skill that secures Docker images and container runtime configurations using non-root users, read-only filesystems, and security contexts.
About
Container Hardening is a skill for securing Docker images and container runtime configurations. It shows how to run containers as a non-root user, enforce a read-only root filesystem, drop Linux capabilities, and set Kubernetes security contexts. A developer uses it when building secure container images or hardening deployments against container escape and privilege escalation.
- Non-root user, read-only filesystem, and dropped capabilities for Docker images
- Kubernetes securityContext hardening (runAsNonRoot, allowPrivilegeEscalation false)
- Distroless base images plus Trivy image scanning for HIGH/CRITICAL CVEs
Container Hardening by the numbers
- 118 all-time installs (skills.sh)
- Ranked #963 of 2,203 Security skills by installs in the Skillselion catalog
- Data as of Jul 28, 2026 (Skillselion catalog sync)
container-hardening capabilities & compatibility
- Capabilities
- container scanning · kubernetes hardening
- Works with
- docker · kubernetes
- Use cases
- devops · security audit
What container-hardening says it does
- Enable read-only filesystem - Drop all capabilities
npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill container-hardeningAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 118 |
|---|---|
| repo stars | ★ 44 |
| Last updated | May 22, 2026 |
| Repository | bagelhole/devops-security-agent-skills ↗ |
What it does
Harden a Docker image and its Kubernetes deployment so containers run non-root with a read-only filesystem and minimal capabilities.
Who is it for?
Developers building secure container images or hardening Docker and Kubernetes deployments against container escape.
Skip if: Scanning images for known CVEs (see container-scanning) or hardening the host OS itself.
When should I use this skill?
Building secure container images, hardening container deployments, or meeting container security requirements.
What you get
A Dockerfile and Kubernetes manifest that run non-root with a read-only filesystem and dropped capabilities.
- Hardened Dockerfile
- Kubernetes pod securityContext
- Trivy scan command
By the numbers
- 7-item hardening best-practices checklist
Files
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
# 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 /appRuntime Security
# 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:latestKubernetes Security Context
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
# Scan with Trivy
trivy image --severity HIGH,CRITICAL myapp:latest
# Use distroless images
FROM gcr.io/distroless/static-debian11Best 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 - Vulnerability scanning
- kubernetes-hardening - K8s security
Container Security Best Practices
Dockerfile Hardening
# Use minimal base image
FROM gcr.io/distroless/base-debian12
# Or Alpine
FROM alpine:3.19
# Non-root user
RUN addgroup -g 1000 appgroup && \
adduser -u 1000 -G appgroup -D appuser
USER appuser
# Read-only filesystem
# (Set at runtime with --read-only)
# No new privileges
# (Set at runtime with --security-opt=no-new-privileges)Security Scanning
# Trivy scan
trivy image --severity HIGH,CRITICAL myimage:latest
# Grype scan
grype myimage:latest --fail-on high
# Docker Scout
docker scout cves myimage:latestRuntime Security
# Kubernetes securityContext
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefaultDocker Run Hardening
docker run \
--read-only \
--tmpfs /tmp \
--security-opt=no-new-privileges:true \
--cap-drop=ALL \
--user 1000:1000 \
--memory=512m \
--cpus=0.5 \
myimageImage Signing
# Cosign
cosign sign --key cosign.key myimage:latest
cosign verify --key cosign.pub myimage:latest
# Docker Content Trust
export DOCKER_CONTENT_TRUST=1
docker push myimage:latestNetwork Policies
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all
spec:
podSelector: {}
policyTypes:
- Ingress
- EgressChecklist
- [ ] Use minimal base images
- [ ] Run as non-root
- [ ] Drop all capabilities
- [ ] Read-only filesystem
- [ ] No privilege escalation
- [ ] Scan for vulnerabilities
- [ ] Sign images
- [ ] Implement network policies
- [ ] Use secrets management
- [ ] Enable audit logging
Related skills
FAQ
How do I stop a container from running as root?
Create a dedicated user and group in the Dockerfile, COPY files with --chown to that user, and set USER appuser; in Kubernetes set runAsNonRoot: true and runAsUser.
How do I enforce a read-only filesystem?
Run docker with --read-only and mount --tmpfs /tmp, or set readOnlyRootFilesystem: true in the Kubernetes container securityContext.