skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
full-stack-skills/docker-skills106 installs

docker-security

Guidance for Docker security hardening across the full lifecycle — image security (minimal base images, non-root users, pinned versions), runtime security (seccomp/AppArmor/SELinux, capabilities, read-only rootfs, no-new-privileges), secrets management (BuildKit secrets, Docker secrets in Swarm), Docker Bench Security auditing, CIS compliance checklist, and supply-chain security (image signing, content trust, SBOM). Use when the user asks about Docker security, image hardening, non-root containers, seccomp, AppArmor, Docker Bench, secrets management, or securing containers. 使用场景:docker 安全、镜像安全、非root运行、seccomp、AppArmor、security、Docker Bench、secret管理.

How do I install this agent skill?

npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-security
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    This skill provides comprehensive and safe guidance for Docker security hardening, including best practices for image creation, runtime configuration, and secrets management. It correctly warns against high-risk practices like using the --privileged flag and mounting the Docker socket, while recommending standard industry tools like Docker Bench Security.

  • Socketwarn

    1 alert: gptAnomaly

  • Snykpass

    Risk: LOW · No issues

What does this agent skill do?

Docker Security — 安全加固与防护

Comprehensive guidance for securing Docker across the full lifecycle.

When to Use

ALWAYS use this skill when the user mentions:

  • "docker 安全", "镜像安全", "container security"
  • "非root运行", "rootless", "least privilege"
  • "seccomp", "AppArmor", "SELinux"
  • "Docker Bench", "CIS"
  • "secrets management", "密钥管理"
  • "image signing", "content trust"

Security Model — Layered Defense

Layer 1: Image Security    — minimal base, non-root, pinned versions
Layer 2: Build Security    — secret injection, noCOPY secrets
Layer 3: Runtime Security  — capabilities, seccomp, AppArmor, read-only
Layer 4: Registry Security — content trust, signing, vulnerability scan
Layer 5: Host Security     — Docker Bench, CIS, user namespace

Image Security Checklist

#PracticeHow
1Minimal base imageUse alpine or distroless (Go → scratch)
2Non-root userUSER 1000:1000 at end of Dockerfile
3Pin versionsFROM alpine:3.20@sha256:... not alpine:latest
4COPY over ADDADD auto-extracts tar — unexpected behavior
5No secrets in imageUse --secret or runtime injection
6.dockerignoreExclude .env, .git, credentials

Secure Dockerfile

FROM alpine:3.20
RUN apk add --no-cache ca-certificates
RUN addgroup -S app && adduser -S -G app app
COPY --chown=app:app ./app /app
WORKDIR /app
USER app
CMD ["./server"]

Runtime Security

Capabilities (Least Privilege)

# Drop ALL capabilities, add only what's needed
docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE nginx

# Common needed caps: NET_BIND_SERVICE, CHOWN, DAC_OVERRIDE
# NEVER: --privileged (gives full host access)

Read-Only Root Filesystem

# Prevents container from writing anywhere (except volumes/tmpfs)
docker run --read-only --tmpfs /tmp --tmpfs /run nginx

Seccomp Profile

# Custom seccomp profile (block syscalls)
docker run --security-opt seccomp=profile.json app

# Unconfined (NEVER in production)
docker run --security-opt seccomp=unconfined app

No New Privileges

# Prevent privilege escalation via setuid binaries
docker run --security-opt no-new-privileges app

Secrets Management

BuildKit Secrets (build-time)

# syntax=docker/dockerfile:1
FROM alpine
RUN --mount=type=secret,id=aws_creds \
  AWS_ACCESS_KEY_ID=$(cat /run/secrets/aws_creds) \
  aws s3 cp s3://bucket/file .
docker build --secret id=aws_creds,src=$HOME/.aws/credentials -t app .

Docker Secrets (Swarm runtime)

echo "mysecretpassword" | docker secret create db_password -
docker service create --secret db_password postgres

Docker Bench Security Audit

docker run --rm \
  --pid host --network host \
  -v /var/run/docker.sock:/var/run/docker.sock \
  docker/docker-bench-security

Workflow — 安全加固流程

Step 1: 镜像安全: docker scout cves <image> 扫描漏洞 → 更新基础镜像/依赖 Step 2: Dockerfile 加固: USER 非 root、COPY 优于 ADD、固定 digest Step 3: 运行时安全: --read-only、--cap-drop=ALL、--security-opt no-new-privileges Step 4: 审计检查: docker run --rm docker/docker-bench-security 逐条修复 Step 5: CI 门禁: Scout 策略阻断 critical/high CVE 合并

Gotchas — Common Pitfalls

  • --privileged flag: Gives full host access. Never use in production. → Recovery: Use specific --cap-add=NET_BIND_SERVICE instead; audit with docker inspect --format='{{.HostConfig.Privileged}}'.
  • API keys in Dockerfile: ENV API_KEY=xxx is baked into image layers forever. → Recovery: Use runtime injection: docker run -e API_KEY=$KEY or BuildKit --mount=type=secret.
  • Root container: Default user is root. Escaping the container means root on the host. → Recovery: Always USER 1000:1000 in Dockerfile; verify with docker exec myapp whoami.
  • Docker socket mount: -v /var/run/docker.sock gives container control over ALL containers. → Recovery: Use Docker API with TLS auth instead of socket mount; never mount socket in production.
  • Ignoring CVE remediation: Running docker scout but never fixing findings. → Recovery: Set CI policy to block critical/high CVEs; update base images regularly.

Boundary — 能力边界(适用与不适用场景)

分类场景说明
✅ 能做Dockerfile 安全加固USER 非 root、COPY 优先 ADD、digest 固定
✅ 能做运行时安全配置seccomp/AppArmor/capabilities/read-only
✅ 能做Secrets 管理Docker secrets + BuildKit --secret + Vault
✅ 能做安全审计(Docker Bench Security)CIS 检查清单 + 逐条修复
⚠️ 需条件镜像签名(Notary)需 DOCKER_CONTENT_TRUST=1 环境变量
⚠️ 需条件完整合规检查需结合 Scout 扫描 + 组织安全策略
❌ 超范围CVE 漏洞扫描使用 docker-scout
❌ 超范围主机系统安全操作系统层级
❌ 超范围网络安全/防火墙网络管理员范畴

When NOT to Use This Skill

❌ Skip✅ Use Instead
Vulnerability scanningdocker-scout
Docker basicsdocker-basics
Production deploymentdocker-production
Registry managementdocker-hub

Security & Stability

  • All security practices are based on CIS Docker Benchmark and Docker official security guidance.
  • Run Docker Bench Security regularly in CI/CD to detect configuration drift.
  • Subscribe to Docker security advisories for CVE notifications.
  • No executable scripts bundled. Guidance only.

📚 官方文档参考

文档地址
Docker 安全https://docs.docker.com/security/
Docker Hardened Imageshttps://docs.docker.com/dhi/
Docker Scouthttps://docs.docker.com/scout/
Docker Bench Securityhttps://docs.docker.com/engine/security/bench/
seccomp 配置https://docs.docker.com/engine/security/seccomp/
AppArmorhttps://docs.docker.com/engine/security/apparmor/

🧭 Docker Skills Journey

📍 You are here: docker-security — 安全加固

← Previous: docker-build | → Next: docker-scout / docker-cicd

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/full-stack-skills/docker-skills/docker-security">View docker-security on skillZs</a>