Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
full-statck-skills avatar

Docker Security

  • 11 installs
  • 2 repo stars
  • Updated July 29, 2026
  • full-statck-skills/docker-skills

Harden Docker across image, runtime, and host layers with non-root users, seccomp/AppArmor, secrets management, and Docker Bench/CIS auditing.

About

Guides Docker security hardening across image, build, runtime, registry, and host layers. A developer uses it to secure containers and pass CIS/Docker Bench audits.

  • Image hardening: minimal base, non-root users, pinned versions, .dockerignore
  • Runtime security with seccomp/AppArmor/capabilities, secrets management, and Docker Bench/CIS auditing

Docker Security by the numbers

  • 11 all-time installs (skills.sh)
  • Ranked #1,660 of 2,203 Security skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/docker-skills --skill docker-security

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs11
repo stars2
Last updatedJuly 29, 2026
Repositoryfull-statck-skills/docker-skills

What it does

Harden Docker across image, runtime, and host layers with non-root users, seccomp/AppArmor, secrets management, and Docker Bench/CIS auditing.

Files

SKILL.mdMarkdownGitHub ↗

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`.dockerignore`Exclude .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

Related skills

Securityappsecsecrets

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.