跳到主内容
智客 ZICQ

技能库 智客分类:安全测试 docker

Docker

建立并调试多克文件、编译、多克/波德曼容器和BuildKit图像;审查容器安全性.

49 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

建立并调试多克文件、编译、多克/波德曼容器和BuildKit图像;审查容器安全性.

何时用

- 编写或审查多克文件(单一或多阶段)

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Docker & Containers: Production Infrastructure、When to use、When NOT to use、AI Self-Check、Performance、Best Practices。 其中含规范建议的小节:分步指令。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/target-versions.md、references/agent-hygiene.md、references/dockerfile-patterns.md、references/compose-patterns.md、references/security-and-compliance.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

· Build and debug Dockerfiles, Compose, Docker/Podman containers, and BuildKit images; review container security.

Docker & Containers: Production InfrastructureWhen to useWhen NOT to useAI Self-CheckPerformanceBest PracticesWorkflowStep 1: Determine the domainStep 2: Gather contextStep 3: BuildStep 4: ValidateDockerfile

兼容:Requires docker or podman. Optional: docker compose, buildkit, cosign, trivy · 许可:MIT

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
docker
description
· Build and debug Dockerfiles, Compose, Docker/Podman containers, and BuildKit images; review container security.
compatibility
Requires docker or podman. Optional: docker compose, buildkit, cosign, trivy
许可
MIT
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 5
  • references/target-versions.md
  • references/agent-hygiene.md
  • references/dockerfile-patterns.md
  • references/compose-patterns.md
  • references/security-and-compliance.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「docker」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-28493b000858932c-%E5%A4%B9%E5%85%8B.html
请存为 .cursor/skills/docker/SKILL.md 或 .claude/skills/docker/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/iuliandita/skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/iuliandita/skills' --list

npx skills add 'https://github.com/iuliandita/skills' --skill 'docker'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: docker description: > · Build and debug Dockerfiles, Compose, Docker/Podman containers, and BuildKit images; review container security. license: MIT compatibility: "Requires docker or podman. Optional: docker compose, buildkit, cosign, trivy" metadata: source: iuliandita/skills date_added: "2026-03-24" effort: high argument_hint: "[dockerfile-or-compose-or-task]" --- # Docker & Containers: Production Infrastructure Write, review, and architect Dockerfiles, Compose stacks, and container workflows - from single-service dev setups to multi-arch production pipelines with image signing and compliance gates. The goal is minimal, secure, reproducible images that a team can maintain and a QSA can audit. **Target versions**: September 2026 snapshot. Read `references/target-versions.md` before pinning Docker, Compose, BuildKit, containerd, Podman, Buildah, or runc. **Portable metadata:** keep file-routing patterns in the description and scope sections. `paths` is a Claude Code-local extension, not portable Agent Skills metadata, and can make claude.ai uploads or Skills API packages fail validation. This skill covers Dockerfiles, Compose, container hardening, supply chain, registry/CI patterns, and runtime migration across Docker, Podman, Buildah, Skopeo, and containerd. ## When to use - Writing or reviewing Dockerfiles (single or multi-stage) - Setting up Docker Compose stacks (dev, staging, production) - Optimizing image size, build speed, or layer caching - Hardening containers for production or compliance - Setting up image signing, SBOM generation, or vulnerability scanning - Containerizing AI/ML workloads (Model Runner, GPU passthrough, model serving) - Migrating from Docker to Podman or building with Buildah - Reviewing container security posture for PCI-DSS 4.0 or SOC 2 - Troubleshooting container networking, volume, or build issues - Using `docker init` to scaffold a new project ## When NOT to use - Kubernetes manifests, Helm charts, cluster architecture (use **kubernetes**) - CI/CD pipeline design (use **ci-cd**) - Security audits of application code (use **security-audit**) - Infrastructure provisioning with Terraform (use **terraform**) ## AI Self-Check AI tools consistently produce the same Docker mistakes. **Before returning any generated Dockerfile or Compose file, verify against this list:** - [ ] Multi-stage build used when the app has a build step (TypeScript, Go, Rust, Java, C/C++) - [ ] Dependencies copied and installed BEFORE source code (layer caching) - [ ] Final image is slim/distroless/scratch - no build tools, no package caches - [ ] `USER` directive present - container does NOT run as root - [ ] No secrets in `ENV`, `ARG`, or `COPY` - use `--mount=type=secret` or runtime injection - [ ] Production base image resolved to a SHA256 digest; illustrative major/minor tags in templates must be resolved before release - [ ] Long-running production services have a meaningful health probe in the image or orchestrator; one-shot jobs use exit status - [ ] `.dockerignore` exists and excludes `.git`, `node_modules`, `.env`, `__pycache__`, etc. - [ ] No `ADD` for local files (use `COPY` - `ADD` auto-extracts and fetches URLs) - [ ] Compose: no `version:` field (deprecated since Compose v2, removed in spec v5) - [ ] Compose: `depends_on` uses `condition: service_healthy`, not bare ordering - [ ] Compose: resource limits set on production services - [ ] Package caches cleaned in same layer: `--no-cache` (apk), `rm -rf /var/lib/apt/lists/*` (apt). For pip: use `--mount=type=cache` OR `--no-cache-dir`, not both. - [ ] CMD uses exec form (JSON array), not shell form: `CMD ["node", "app.js"]` not `CMD node app.js` - [ ] **HEALTHCHECK uses available tools**: probe command uses a binary present in the final image (wget in Alpine, curl in Debian, none in scratch/distroless - use the app's own health endpoint) - [ ] **Engine/Compose syntax checked**: Dockerfile, Compose, BuildKit, and runtime flags match the installed versions - [ ] **Image provenance considered**: base images, registries, tags, SBOMs, and signatures are handled where risk warrants - [ ] Cross-cutting agent hygiene applied - see `references/agent-hygiene.md` ## Performance - Order Dockerfile layers from stable to volatile and use cache mounts for package-manager caches where BuildKit is available. - Keep build contexts small with `.dockerignore`; accidental monorepo contexts dominate build time. - Use multi-stage builds and slim runtime images, but measure startup and debug needs before stripping tools aggressively. ## Best Practices - Pin base image digests for sensitive workloads and track rebuild cadence for security updates. - Run as non-root and drop capabilities unless the workload genuinely needs them. - Preview prune and volume-removal commands; persistent data must never be collateral cleanup. ## Workflow ### Step 1: Determine the domain Based on the request: - **"Write a Dockerfile" / "containerize this app"** -> Dockerfile - **"Set up docker compose" / "multi-service stack"** -> Compose - **"Harden this" / "make PCI compliant" / "scan for vulnerabilities"** -> Security - **"Sign images" / "generate SBOM" / "CI pipeline"** -> Registry & CI - **"Use Podman" / "rootless containers" / "daemonless builds"** -> Runtimes - **"Review this Dockerfile/compose"** -> Apply production checklist + AI self-check ### Step 2: Gather context Before writing anything, determine: - **Application type**: language, framework, build system - **Runtime**: Bun, Node.js, Python, Go, Rust, Java - determines base image and build pattern - **Environment**: dev (hot reload, debug) vs production (minimal, hardened) - **Base image**: Alpine (small, musl) vs Debian-slim (glibc compat) vs distroless (no shell) vs Chainguard (zero-CVE) vs scratch (static binaries) - **Secrets**: how are they injected? (env vars, mounted files, Docker secrets, vault) - **Compliance**: PCI CDE? Regulated? What scanning/signing is required? - **Target registry**: Docker Hub, GHCR, private registry, OCI-compliant? - **AI/ML**: GPU workload? Model serving? Docker Model Runner? ### Step 3: Build Follow the domain-specific section below. Always apply the production checklist (Step 4) and AI self-check before finishing. ### Step 4: Validate ```bash # Dockerfile docker build -t test-build . # Use --no-cache only when investigating stale cache or clean-build reproducibility docker history test-build --format "{{.Size}}\t{{.CreatedBy}}" | head -15 docker scout quickview test-build # vulnerability overview docker scout cves test-build # detailed CVE list # Compose docker compose config # validate and render docker compose --dry-run up # dry-run startup (Compose v5) # Security docker scout cves --only-severity critical,high cosign verify --key # verify signature syft -o spdx-json # generate SBOM grype # vulnerability scan (alternative to Scout) trivy image # use v0.74.0+; never v0.69.4-6 ``` ## Dockerfile Read `references/dockerfile-patterns.md` for complete, production-ready Dockerfile templates (Node.js/Bun, Python, Go, Rust, static site) and BuildKit syntax reference. ### Base image selection - Need a shell or package manager: use slim Debian or Ubuntu bases. - Need the smallest static runtime: use distroless or `scratch`. - Need a hardened minimal userspace: use Chainguard or another verified Wolfi-style base. - Keep builders and runtimes separate; `golang`, `rust`, and other heavy toolchain images stay in build stages only. See `references/dockerfile-patterns.md` for the actual language-by-language base recommendations and templates. ### Key patterns **Multi-stage builds** - the non-negotiable pattern for any compiled or transpiled language: ```dockerfile # syntax=docker/dockerfile:1 FROM node:22-slim AS build WORKDIR /app COPY package.json package-lock.json ./ RUN --mount=type=cache,target=/root/.npm \ npm ci COPY . . RUN npm run build && npm prune --omit=dev FROM gcr.io/distroless/nodejs22-debian12 WORKDIR /app COPY --from=build --chown=1001:1001 /app/dist ./dist COPY --from=build --chown=1001:1001 /app/node_modules ./node_modules USER 1001 EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ CMD ["node", "-e", "fetch('http://localhost:3000/health').then(r=>r.ok||process.exit(1)).catch(()=>process.exit(1))"] CMD ["dist/index.js"] ``` **BuildKit features** (require `# syntax=docker/dockerfile:1` or `DOCKER_BUILDKIT=1`): - **Cache mounts**: `RUN --mount=type=cache,target=/root/.npm npm ci` - persists package cache across builds, up to 70% faster rebuilds - **Secret mounts**: `RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci` - secrets never baked into layers - **Heredocs**: multi-line scripts without backslash hell ```dockerfile RUN <= 1.4.0, BuildKit to >= 0.31.2, Docker Desktop to >= 4.71.0 (prefer the current 4.90.0 snapshot), never pull Trivy v0.69.4/5/6. Pin ALL CI tool images to SHA256 digests. ### Hardened Compose baseline Every production service should start from this, relax only what's needed: ```yaml services: app: image: myapp:1.0.0 # pinned, never :latest read_only: true security_opt: - no-new-privileges:true cap_drop: - ALL cap_add: [] # add ONLY what's needed (see note below) tmpfs: - /tmp user: "1001:1001" healthcheck: test: ["CMD-SHELL", "wget -qO /dev/null http://localhost:8080/health || exit 1"] interval: 30s timeout: 5s start_period: 15s retries: 3 deploy: resources: limits: memory: 512M cpus: "1.0" logging: driver: json-file options: max-size: "10m" max-file: "3" ``` **`cap_drop: ALL` warning**: many images (LSIO, HOTIO, official redis/postgres, anything using gosu/setpriv/su-exec) start as root and drop privileges at runtime. They need at minimum `cap_add: ["SETUID", "SETGID"]`, and images that chown files at startup also need `"CHOWN"`. Always read the image's entrypoint to determine required capabilities before applying blanket drops. Blind `cap_drop: ALL` with empty `cap_add` causes CrashLoopBackOff. See the security-audit skill's "No blanket capability drops" rule for detailed guidance. For a hardened Dockerfile pattern, see `references/dockerfile-patterns.md` (Language Templates section). ### Supply chain security - **Sign images** with cosign (Sigstore): `cosign sign --key cosign.key @` - **Generate SBOMs** at build time: `docker scout sbom ` or `syft -o spdx-json` - **Verify at deploy**: `cosign verify --key cosign.pub @` - **Pin CI tool images to SHA256 digests.** Mutable tags are a proven attack vector (Trivy March 2026, tj-actions/reviewdog March 2025). - **Use Docker Scout** or Grype for continuous vulnerability monitoring. - **Trivy**: use v0.74.0+ from official releases for new pins. v0.69.3 was the March 2026 rollback version. v0.69.4-6 contained credential-stealing malware. If any CI pipeline ran compromised Trivy between March 19-23, 2026, rotate ALL secrets. ### PCI-DSS 4.0 container requirements (summary) PCI-DSS 4.0 is the only active version. Key container-specific requirements: - **Req 1**: Network segmentation - use user-defined bridge networks, `internal: true` for backend services, never expose CDE containers on default bridge - **Req 2.2**: Harden containers - non-root, drop caps, read-only rootfs, one process per container - **Req 4**: Encrypt transmissions - TLS between CDE containers in Compose (mount certs, use TLS-enabled images, or front with a TLS-terminating reverse proxy) - **Req 5.2/5.3**: Immutable images (deploy by digest), Falco for runtime detection - **Req 6.3**: Vulnerability scanning on every image before deployment (Docker Scout, Grype, Trivy v0.74.0+) - **Req 6.3.2**: SBOM for every production image - **Req 8.6.2**: No hardcoded secrets in images, compose files, or env vars - **Req 10**: Audit logging - container stdout/stderr to immutable log store - **Req 11.5**: Image digest pinning + Falco = FIM for containers Full mapping in `references/security-and-compliance.md`. ## Registry & CI ### CI pipeline pattern - Build with `docker build --check` first, then `buildx` with provenance and SBOM output. - Scan before deploy, sign by digest, and keep an SBOM artifact even if the registry also stores one. - Pin CI-side tools and actions to immutable digests, not mutable tags. ### Docker Model Runner (AI/ML) Docker Model Runner (Engine 29.x, Desktop 4.50+) serves AI models via OpenAI/Ollama-compatible APIs: ```yaml # Compose integration with Model Runner services: model: provider: type: model options: model: ai/llama3.2:3B-Q4_K_M agent: build: . environment: OPENAI_BASE_URL: http://model/v1 ``` GPU containers: use `deploy.resources.reservations.devices` with `capabilities: [gpu]`. Start `shm_size` at `16gb` for single GPU, `32gb` for multi-GPU (vLLM needs shared memory for tensor ops). See `references/compose-patterns.md` for the full AI/ML stack template. ## Production Checklist See AI Self-Check above for the full build-time checklist (Dockerfile correctness, Compose structure, layer caching, secrets, non-root user, healthchecks, base image pinning). The items below cover deploy-time and operational additions only. ### Deploy-time additions - [ ] runc >= 1.4.0 (CVE-2025-31133/52565/52881 patched) - [ ] BuildKit >= 0.31.2 (includes CVE-2026-15793 and CVE-2026-33747/33748 fixes) - [ ] Docker Desktop >= 4.71.0 (adds CVE-2026-5817/5843 Model Runner container-to-host RCE fixes; floor was 4.66.1 for CVE-2025-9074/CVE-2026-28400) - [ ] Trivy v0.74.0+ from official releases (v0.69.4-6 COMPROMISED) - [ ] Images signed with cosign, verified at deploy - [ ] SBOM generated for every production image - [ ] Vulnerability scanning in CI (Docker Scout, Grype, or Trivy v0.74.0+) - [ ] CI tools pinned to SHA256 digests (not mutable tags) - [ ] Base images rebuilt/updated regularly (weekly minimum) - [ ] Separate override files for dev/prod - [ ] Logging config with rotation (`max-size`, `max-file`) - [ ] `read_only: true` + `no-new-privileges` + `cap_drop: ALL` on production services ### Compliance (PCI-DSS 4.0) - [ ] Containers run as non-root with minimal capabilities (Req 2.2) - [ ] Read-only root filesystem, one process per container (Req 2.2) - [ ] Images scanned for vulnerabilities before deployment (Req 6.3) - [ ] SBOM generated for every CDE image (Req 6.3.2) - [ ] No hardcoded secrets in images or compose files (Req 8.6.2) - [ ] Image digests pinned for immutability (Req 5/11.5) - [ ] Container logs shipped to immutable SIEM (Req 10) - [ ] Runtime detection in place (Falco/Tetragon) (Req 5.2/5.3) - [ ] Registry access audit-logged (Req 10.4.1.1) - [ ] Base images from trusted, verified sources (Req 6.2.1) ## Reference Files - `references/dockerfile-patterns.md` - Dockerfile templates and build patterns - `references/compose-patterns.md` - Compose patterns and common stack layouts - `references/security-and-compliance.md` - container hardening, compliance guidance, and safe public custom image publishing - `references/alternative-runtimes.md` - Podman, Buildah, Skopeo, and related runtime patterns - `references/target-versions.md` - September 2026 version snapshot for Docker, Compose, BuildKit, containerd, Podman, Buildah, and runc ## Output Contract See `references/output-contract.md` for the full contract. - **Skill name:** DOCKER - **Deliverable bucket:** `audits` - **Mode:** conditional. When invoked to **analyze, review, audit, or improve** existing repo content, emit the full contract - monospace inline header, severity-grouped inline summary, linked Markdown deliverable, and concise monospace conclusion - and write the deliverable to `docs/local/audits/docker/-.md`. When invoked to **answer a question, teach a concept, build a new artifact, or generate content**, respond freely without the contract. - **Severity scale:** `P0 | P1 | P2 | P3 | info` (see shared contract; only used in audit/review mode). ## Related Skills - **kubernetes** - for deploying containers to K8s clusters. Docker builds the image; kubernetes deploys it. Dockerfile optimization belongs here; K8s manifests belong there. - **ci-cd** - for pipeline design that builds and pushes images. Docker skill covers the Dockerfile and Compose patterns; ci-cd covers the pipeline stages around them. - **security-audit** - for auditing container images, scanning for CVEs, and supply chain risks. Docker skill covers hardening best practices; security-audit runs the actual audit. - **ansible** - can manage containers via `community.docker`, but image building and Compose design belong here. - **databases** - for database containers in Docker Compose. Docker skill owns the Compose pattern; databases skill owns the engine tuning within the container. - **git** - for git tags and version control. Docker skill handles container image tagging; git handles git tags and release workflows. ## Rules 1. **Resolve production images to digests.** Template tags illustrate image families; they are mutable and do not establish reproducibility. 2. **Multi-stage builds for compiled/transpiled languages.** Build tools do not belong in production images. 3. **Non-root user.** Every production container must run as non-root (numeric UID for K8s compat). 4. **No secrets in layers.** Not in `ENV`, not in `ARG`, not in `COPY`. Use `--mount=type=secret` or runtime injection. 5. **Deps before source.** Copy dependency manifests first, install, then copy source. Layer cache depends on it. 6. **Meaningful service healthchecks.** Use Dockerfile, Compose, or orchestrator probes for long-running services; use exit status for one-shot jobs and document external monitoring. 7. **Pin CI tools to SHA256 digests.** Mutable tags are compromised supply chain vectors (Trivy CVE-2026-33634 March 2026, tj-actions CVE-2025-30066 (upstream: reviewdog CVE-2025-30154) March 2025). 8. **Trivy v0.74.0+ for new pins.** v0.69.3 was the March 2026 rollback version; v0.69.4-6 contained credential-stealing malware. If you ran it, rotate secrets. 9. **Compose: no `version:` field.** It's deprecated and removed. Just delete it. 10. **Clean apt cache in the same RUN layer.** `apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*` - all one `RUN`. 11. **`.dockerignore` is not optional.** `.git`, `node_modules`, `.env`, secrets, test fixtures, docs - all excluded. 12. **Resource limits on production containers.** Memory and CPU limits prevent noisy neighbors and OOM cascading. 13. **Run the AI self-check.** Every generated Dockerfile/Compose gets verified against the checklist above before returning.

相关技能

安全测试

Skill Vetter

人工智能特工的安全第一技能审查。 在安装来自 ClawdHub, GitHub 或其他来源的任何技能之前使用 。 检查红旗,许可范围,可疑图案.

安全测试

Moltguard

MoltGuard——由OpenGuardrails担任OpenClaw保安. 安装 MoltGuard 以保护你和你的人类免受迅速注射、数据过滤和恶意命令的影响。 资料来源:https://github.com/openguardrails/openguardrails/tre…

安全测试

Security Auditor

用于审查安全漏洞代码,实施认证流,审计OWASP Top 10,配置CORS/CSP头,处理秘密,输入验证,SQL注射预防,XSS保护,或任何与安全相关的代码审查.

安全测试

Skill Vetter

安装任何AI代理技能前的安全审查协议. 红旗侦取入证盗取,疏通密码,放出. 风险分类:低/中/高/高。 编制结构化审查报告。 不先运行此功能, 绝不安装不信任的技能 .