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
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
Base image pinned to specific version or SHA256 digest (never :latest except Chainguard free tier, never bare :22)
HEALTHCHECK present for production images
.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
docker init: scaffolds Dockerfile + compose.yaml + .dockerignore. Good starting point, always review.
What NOT to write
COPY . . before dependency install (busts cache on every source change)
ADD for local files (use COPY - ADD is only for auto-extracting .tar.gz archives into the image)
MAINTAINER (deprecated - use LABEL maintainer="...")
RUN cd /dir && ... (use WORKDIR /dir)
Separate RUN for each package install (chain with &&)
chmod 777 on anything
Secrets in ARG or ENV
FROM node:latest or FROM python (unpinned)
ENTRYPOINT + CMD together unless ENTRYPOINT is the binary and CMD is overridable default args (e.g., ENTRYPOINT ["/app"] + CMD ["--config", "/etc/app.yaml"])
Compose
Read references/compose-patterns.md for complete Compose v5 templates (web+db, dev override, production hardened, AI/ML stack) and network/volume patterns.
Compose v5
Do not use the old version: field.
Expect Bake-based builds, watch, dry-run validation, and newer model-oriented service wiring.
Keep dev and prod concerns separate; override files are still the sane default.
Treat healthchecks and dependency readiness as normal Compose design, not optional extras.
Secrets: use top-level secrets: with file: or external: true, reference via _FILE env convention (e.g., POSTGRES_PASSWORD_FILE: /run/secrets/db_pass). Never hardcode secrets in environment:. See references/compose-patterns.md for the full template with secret wiring.
Health-gated dependencies: always use depends_on: with condition: service_healthy - bare depends_on is ordering only, no readiness guarantee.
Compose anti-patterns
version: "3.8" - dead field, remove it
container_name on every service (breaks docker compose up --scale)
restart: always without healthcheck (infinite restart of broken containers)
network_mode: host when port mapping works (replace with a user-defined bridge network and explicit ports: mapping)
depends_on without condition: (ordering only, no readiness)
volumes: mounting entire project dir in production (dev pattern leak)
privileged: true on a compose service instead of the host LXC
20+ inline environment: entries (use env_file:)
Security
Read references/security-and-compliance.md for the full PCI-DSS 4.0 container requirements mapping, CVE reference, runtime hardening patterns, and scanning tool comparison.
Critical vulnerabilities (2025-2026)
CVE
Component
Severity
Impact
Fixed in
CVE-2025-9074
Docker Desktop
9.3 Critical
Container escape via unauthenticated Engine API
Desktop 4.44.3
CVE-2025-31133
runc
High
Container escape via /dev/null symlink race
runc 1.2.8, 1.3.3, 1.4.0-rc.3
CVE-2025-52565
runc
High
Container escape via /dev/console mount race
runc 1.2.8, 1.3.3, 1.4.0-rc.3
CVE-2025-52881
runc
High
Host procfs writes via /proc redirect (DoS/escape)
runc 1.2.8, 1.3.3, 1.4.0-rc.3
CVE-2026-33634
Trivy
Critical
Supply chain - malware in Docker Hub images (v0.69.4-6)
Trivy v0.74.0+ for new pins; v0.69.3 only as rollback
CVE-2026-2664
Docker Desktop
Medium
gRPC-FUSE kernel module OOB read
Desktop 4.62.0+
CVE-2025-13743
Docker Desktop
Low
Expired Hub PATs leaked in diagnostics bundles
Desktop 4.54.0
CVE-2026-28400
Model Runner
7.5 High
Runtime flag injection - arbitrary file overwrite, container escape
Desktop 4.61.0+
CVE-2026-5843
Model Runner (MLX)
8.8 High
Container-to-host code execution via MLX-LM model_file importlib load from untrusted models
Desktop 4.71.0+
CVE-2026-5817
Model Runner (vllm-metal)
8.8 High
Container-to-host RCE via unsandboxed trust_remote_code tokenizer load
Action items: upgrade runc to >= 1.4.0, BuildKit to >= 0.28.1, Docker Desktop to >= 4.71.0 (prefer the current 4.86.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:
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 <image>@<digest>
Generate SBOMs at build time: docker scout sbom <image> or syft <image> -o spdx-json
Verify at deploy: cosign verify --key cosign.pub <image>@<digest>
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:
# 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.
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/<YYYY-MM-DD>-<slug>.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
No :latest tags in production. Pin images to a specific version or SHA256 digest.
Multi-stage builds for compiled/transpiled languages. Build tools do not belong in production images.
Non-root user. Every production container must run as non-root (numeric UID for K8s compat).
No secrets in layers. Not in ENV, not in ARG, not in COPY. Use --mount=type=secret or runtime injection.
Deps before source. Copy dependency manifests first, install, then copy source. Layer cache depends on it.
Healthchecks on everything. Dockerfile HEALTHCHECK and Compose healthcheck:.
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).
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.
Compose: no version: field. It's deprecated and removed. Just delete it.
Clean apt cache in the same RUN layer.apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/* - all one RUN.
.dockerignore is not optional..git, node_modules, .env, secrets, test fixtures, docs - all excluded.
Resource limits on production containers. Memory and CPU limits prevent noisy neighbors and OOM cascading.
Run the AI self-check. Every generated Dockerfile/Compose gets verified against the checklist above before returning.
1---2name: docker3description: >4 · Write/review Dockerfiles, Compose, OCI/Podman/BuildKit builds, signing, hardening. Triggers: 'docker', 'dockerfile', 'podman', 'buildkit', 'buildah', 'skopeo', 'containerd'. Not for K8s manifests (use kubernetes).5license: MIT6compatibility: "Requires docker or podman. Optional: docker compose, buildkit, cosign, trivy"7metadata:8 source: iuliandita/skills9 date_added: "2026-03-24"10 effort: high11 argument_hint: "[dockerfile-or-compose-or-task]"12---1314# Docker & Containers: Production Infrastructure1516Write, 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.1718**Target versions**: September 2026 snapshot. Read `references/target-versions.md` before19pinning Docker, Compose, BuildKit, containerd, Podman, Buildah, or runc.2021**Portable metadata:** keep file-routing patterns in the description and scope sections. `paths`22is a Claude Code-local extension, not portable Agent Skills metadata, and can make claude.ai uploads23or Skills API packages fail validation.2425This skill covers Dockerfiles, Compose, container hardening, supply chain, registry/CI26patterns, and runtime migration across Docker, Podman, Buildah, Skopeo, and containerd.2728## When to use2930- Writing or reviewing Dockerfiles (single or multi-stage)31- Setting up Docker Compose stacks (dev, staging, production)32- Optimizing image size, build speed, or layer caching33- Hardening containers for production or compliance34- Setting up image signing, SBOM generation, or vulnerability scanning35- Containerizing AI/ML workloads (Model Runner, GPU passthrough, model serving)36- Migrating from Docker to Podman or building with Buildah37- Reviewing container security posture for PCI-DSS 4.0 or SOC 238- Troubleshooting container networking, volume, or build issues39- Using `docker init` to scaffold a new project4041## When NOT to use4243- Kubernetes manifests, Helm charts, cluster architecture (use **kubernetes**)44- CI/CD pipeline design (use **ci-cd**)45- Security audits of application code (use **security-audit**)46- Infrastructure provisioning with Terraform (use **terraform**)4748## AI Self-Check4950AI tools consistently produce the same Docker mistakes. **Before returning any generated Dockerfile or Compose file, verify against this list:**5152- [ ] Multi-stage build used when the app has a build step (TypeScript, Go, Rust, Java, C/C++)53- [ ] Dependencies copied and installed BEFORE source code (layer caching)54- [ ] Final image is slim/distroless/scratch - no build tools, no package caches55- [ ] `USER` directive present - container does NOT run as root56- [ ] No secrets in `ENV`, `ARG`, or `COPY` - use `--mount=type=secret` or runtime injection57- [ ] Base image pinned to specific version or SHA256 digest (never `:latest` except Chainguard free tier, never bare `:22`)58- [ ] `HEALTHCHECK` present for production images59- [ ] `.dockerignore` exists and excludes `.git`, `node_modules`, `.env`, `__pycache__`, etc.60- [ ] No `ADD` for local files (use `COPY` - `ADD` auto-extracts and fetches URLs)61- [ ] Compose: no `version:` field (deprecated since Compose v2, removed in spec v5)62- [ ] Compose: `depends_on` uses `condition: service_healthy`, not bare ordering63- [ ] Compose: resource limits set on production services64- [ ] 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.65- [ ] CMD uses exec form (JSON array), not shell form: `CMD ["node", "app.js"]` not `CMD node app.js`66- [ ] **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)67- [ ] **Engine/Compose syntax checked**: Dockerfile, Compose, BuildKit, and runtime flags match the installed versions68- [ ] **Image provenance considered**: base images, registries, tags, SBOMs, and signatures are handled where risk warrants69- [ ] Cross-cutting agent hygiene applied - see `references/agent-hygiene.md`7071## Performance7273- Order Dockerfile layers from stable to volatile and use cache mounts for package-manager caches where BuildKit is available.74- Keep build contexts small with `.dockerignore`; accidental monorepo contexts dominate build time.75- Use multi-stage builds and slim runtime images, but measure startup and debug needs before stripping tools aggressively.7677## Best Practices7879- Pin base image digests for sensitive workloads and track rebuild cadence for security updates.80- Run as non-root and drop capabilities unless the workload genuinely needs them.81- Preview prune and volume-removal commands; persistent data must never be collateral cleanup.8283## Workflow8485### Step 1: Determine the domain8687Based on the request:88- **"Write a Dockerfile" / "containerize this app"** -> Dockerfile89- **"Set up docker compose" / "multi-service stack"** -> Compose90- **"Harden this" / "make PCI compliant" / "scan for vulnerabilities"** -> Security91- **"Sign images" / "generate SBOM" / "CI pipeline"** -> Registry & CI92- **"Use Podman" / "rootless containers" / "daemonless builds"** -> Runtimes93- **"Review this Dockerfile/compose"** -> Apply production checklist + AI self-check9495### Step 2: Gather context9697Before writing anything, determine:98- **Application type**: language, framework, build system99- **Runtime**: Bun, Node.js, Python, Go, Rust, Java - determines base image and build pattern100- **Environment**: dev (hot reload, debug) vs production (minimal, hardened)101- **Base image**: Alpine (small, musl) vs Debian-slim (glibc compat) vs distroless (no shell) vs Chainguard (zero-CVE) vs scratch (static binaries)102- **Secrets**: how are they injected? (env vars, mounted files, Docker secrets, vault)103- **Compliance**: PCI CDE? Regulated? What scanning/signing is required?104- **Target registry**: Docker Hub, GHCR, private registry, OCI-compliant?105- **AI/ML**: GPU workload? Model serving? Docker Model Runner?106107### Step 3: Build108109Follow the domain-specific section below. Always apply the production checklist (Step 4) and AI self-check before finishing.110111### Step 4: Validate112113```bash114# Dockerfile115docker build --no-cache -t test-build .116docker history test-build --format "{{.Size}}\t{{.CreatedBy}}" | head -15117docker scout quickview test-build # vulnerability overview118docker scout cves test-build # detailed CVE list119120# Compose121docker compose config # validate and render122docker compose --dry-run up # dry-run startup (Compose v5)123124# Security125docker scout cves --only-severity critical,high <image>126cosign verify --key <key> <image> # verify signature127syft <image> -o spdx-json # generate SBOM128grype <image> # vulnerability scan (alternative to Scout)129trivy image <image> # use v0.74.0+; never v0.69.4-6130```131132## Dockerfile133134Read `references/dockerfile-patterns.md` for complete, production-ready Dockerfile templates (Node.js/Bun, Python, Go, Rust, static site) and BuildKit syntax reference.135136### Base image selection137138- Need a shell or package manager: use slim Debian or Ubuntu bases.139- Need the smallest static runtime: use distroless or `scratch`.140- Need a hardened minimal userspace: use Chainguard or another verified Wolfi-style base.141- Keep builders and runtimes separate; `golang`, `rust`, and other heavy toolchain images stay in build stages only.142143See `references/dockerfile-patterns.md` for the actual language-by-language base recommendations and templates.144145### Key patterns146147**Multi-stage builds** - the non-negotiable pattern for any compiled or transpiled language:148149```dockerfile150# syntax=docker/dockerfile:1151FROM node:22-slim AS build152WORKDIR /app153COPY package.json package-lock.json ./154RUN --mount=type=cache,target=/root/.npm \155 npm ci156COPY . .157RUN npm run build && npm prune --omit=dev158159FROM gcr.io/distroless/nodejs22-debian12160WORKDIR /app161COPY --from=build --chown=1001:1001 /app/dist ./dist162COPY --from=build --chown=1001:1001 /app/node_modules ./node_modules163USER 1001164EXPOSE 3000165HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \166 CMD ["node", "-e", "fetch('http://localhost:3000/health').then(r=>r.ok||process.exit(1)).catch(()=>process.exit(1))"]167CMD ["dist/index.js"]168```169170**BuildKit features** (require `# syntax=docker/dockerfile:1` or `DOCKER_BUILDKIT=1`):171172- **Cache mounts**: `RUN --mount=type=cache,target=/root/.npm npm ci` - persists package cache across builds, up to 70% faster rebuilds173- **Secret mounts**: `RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci` - secrets never baked into layers174- **Heredocs**: multi-line scripts without backslash hell175176```dockerfile177RUN <<EOF178set -e179apt-get update180apt-get install -y --no-install-recommends ca-certificates181rm -rf /var/lib/apt/lists/*182EOF183```184185- **`--check` flag**: `docker build --check .` validates Dockerfile without building (dry-run lint)186- **SLSA provenance**: `docker build --provenance=true --sbom=true .` attaches attestations187188**`docker init`**: scaffolds Dockerfile + compose.yaml + .dockerignore. Good starting point, always review.189190### What NOT to write191192- `COPY . .` before dependency install (busts cache on every source change)193- `ADD` for local files (use `COPY` - `ADD` is only for auto-extracting `.tar.gz` archives into the image)194- `MAINTAINER` (deprecated - use `LABEL maintainer="..."`)195- `RUN cd /dir && ...` (use `WORKDIR /dir`)196- Separate `RUN` for each package install (chain with `&&`)197- `chmod 777` on anything198- Secrets in `ARG` or `ENV`199- `FROM node:latest` or `FROM python` (unpinned)200- `ENTRYPOINT` + `CMD` together unless ENTRYPOINT is the binary and CMD is overridable default args (e.g., `ENTRYPOINT ["/app"]` + `CMD ["--config", "/etc/app.yaml"]`)201202## Compose203204Read `references/compose-patterns.md` for complete Compose v5 templates (web+db, dev override, production hardened, AI/ML stack) and network/volume patterns.205206### Compose v5207208- Do not use the old `version:` field.209- Expect Bake-based builds, `watch`, dry-run validation, and newer model-oriented service wiring.210- Keep dev and prod concerns separate; override files are still the sane default.211- Treat healthchecks and dependency readiness as normal Compose design, not optional extras.212213### Key patterns214215**Dev/prod separation** with override files:216217```yaml218# compose.yaml (base)219services:220 app:221 image: myapp:1.0.0222 healthcheck:223 test: ["CMD-SHELL", "wget -qO /dev/null http://localhost:3000/health || exit 1"]224 interval: 30s225 timeout: 5s226 start_period: 10s227 retries: 3228229# compose.override.yaml (dev - auto-loaded)230services:231 app:232 build: .233 volumes:234 - .:/app235 - /app/node_modules236 environment:237 NODE_ENV: development238 ports:239 - "9229:9229"240 command: bun run dev241```242243**Secrets**: use top-level `secrets:` with `file:` or `external: true`, reference via `_FILE` env convention (e.g., `POSTGRES_PASSWORD_FILE: /run/secrets/db_pass`). Never hardcode secrets in `environment:`. See `references/compose-patterns.md` for the full template with secret wiring.244245**Health-gated dependencies**: always use `depends_on:` with `condition: service_healthy` - bare `depends_on` is ordering only, no readiness guarantee.246247### Compose anti-patterns248249- `version: "3.8"` - dead field, remove it250- `container_name` on every service (breaks `docker compose up --scale`)251- `restart: always` without healthcheck (infinite restart of broken containers)252- `network_mode: host` when port mapping works (replace with a user-defined bridge network and explicit `ports:` mapping)253- `depends_on` without `condition:` (ordering only, no readiness)254- `volumes:` mounting entire project dir in production (dev pattern leak)255- `privileged: true` on a compose service instead of the host LXC256- 20+ inline `environment:` entries (use `env_file:`)257258## Security259260Read `references/security-and-compliance.md` for the full PCI-DSS 4.0 container requirements mapping, CVE reference, runtime hardening patterns, and scanning tool comparison.261262### Critical vulnerabilities (2025-2026)263264| CVE | Component | Severity | Impact | Fixed in |265|-----|-----------|----------|--------|----------|266| CVE-2025-9074 | Docker Desktop | 9.3 Critical | Container escape via unauthenticated Engine API | Desktop 4.44.3 |267| CVE-2025-31133 | runc | High | Container escape via /dev/null symlink race | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |268| CVE-2025-52565 | runc | High | Container escape via /dev/console mount race | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |269| CVE-2025-52881 | runc | High | Host procfs writes via /proc redirect (DoS/escape) | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |270| CVE-2026-33634 | Trivy | Critical | Supply chain - malware in Docker Hub images (v0.69.4-6) | Trivy v0.74.0+ for new pins; v0.69.3 only as rollback |271| CVE-2026-2664 | Docker Desktop | Medium | gRPC-FUSE kernel module OOB read | Desktop 4.62.0+ |272| CVE-2025-13743 | Docker Desktop | Low | Expired Hub PATs leaked in diagnostics bundles | Desktop 4.54.0 |273| CVE-2026-28400 | Model Runner | 7.5 High | Runtime flag injection - arbitrary file overwrite, container escape | Desktop 4.61.0+ |274| CVE-2026-5843 | Model Runner (MLX) | 8.8 High | Container-to-host code execution via MLX-LM `model_file` importlib load from untrusted models | Desktop 4.71.0+ |275| CVE-2026-5817 | Model Runner (vllm-metal) | 8.8 High | Container-to-host RCE via unsandboxed `trust_remote_code` tokenizer load | Desktop 4.68.0+ |276| CVE-2026-33747 | BuildKit | High | Malicious frontend file escape outside storage root | BuildKit v0.28.1 |277| CVE-2026-33748 | BuildKit | High | Git URL validation bypass - restricted file access | BuildKit v0.28.1 |278279**Action items**: upgrade runc to >= 1.4.0, BuildKit to >= 0.28.1, Docker Desktop to >= 4.71.0 (prefer the current 4.86.0 snapshot), never pull Trivy v0.69.4/5/6. Pin ALL CI tool images to SHA256 digests.280281### Hardened Compose baseline282283Every production service should start from this, relax only what's needed:284285```yaml286services:287 app:288 image: myapp:1.0.0 # pinned, never :latest289 read_only: true290 security_opt:291 - no-new-privileges:true292 cap_drop:293 - ALL294 cap_add: [] # add ONLY what's needed (see note below)295 tmpfs:296 - /tmp297 user: "1001:1001"298 healthcheck:299 test: ["CMD-SHELL", "wget -qO /dev/null http://localhost:8080/health || exit 1"]300 interval: 30s301 timeout: 5s302 start_period: 15s303 retries: 3304 deploy:305 resources:306 limits:307 memory: 512M308 cpus: "1.0"309 logging:310 driver: json-file311 options:312 max-size: "10m"313 max-file: "3"314```315316**`cap_drop: ALL` warning**: many images (LSIO, HOTIO, official redis/postgres, anything using317gosu/setpriv/su-exec) start as root and drop privileges at runtime. They need at minimum318`cap_add: ["SETUID", "SETGID"]`, and images that chown files at startup also need `"CHOWN"`.319Always read the image's entrypoint to determine required capabilities before applying blanket320drops. Blind `cap_drop: ALL` with empty `cap_add` causes CrashLoopBackOff. See the321security-audit skill's "No blanket capability drops" rule for detailed guidance.322323For a hardened Dockerfile pattern, see `references/dockerfile-patterns.md` (Language Templates section).324325### Supply chain security326327- **Sign images** with cosign (Sigstore): `cosign sign --key cosign.key <image>@<digest>`328- **Generate SBOMs** at build time: `docker scout sbom <image>` or `syft <image> -o spdx-json`329- **Verify at deploy**: `cosign verify --key cosign.pub <image>@<digest>`330- **Pin CI tool images to SHA256 digests.** Mutable tags are a proven attack vector (Trivy March 2026, tj-actions/reviewdog March 2025).331- **Use Docker Scout** or Grype for continuous vulnerability monitoring.332- **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.333334### PCI-DSS 4.0 container requirements (summary)335336PCI-DSS 4.0 is the only active version. Key container-specific requirements:337338- **Req 1**: Network segmentation - use user-defined bridge networks, `internal: true` for backend services, never expose CDE containers on default bridge339- **Req 2.2**: Harden containers - non-root, drop caps, read-only rootfs, one process per container340- **Req 4**: Encrypt transmissions - TLS between CDE containers in Compose (mount certs, use TLS-enabled images, or front with a TLS-terminating reverse proxy)341- **Req 5.2/5.3**: Immutable images (deploy by digest), Falco for runtime detection342- **Req 6.3**: Vulnerability scanning on every image before deployment (Docker Scout, Grype, Trivy v0.74.0+)343- **Req 6.3.2**: SBOM for every production image344- **Req 8.6.2**: No hardcoded secrets in images, compose files, or env vars345- **Req 10**: Audit logging - container stdout/stderr to immutable log store346- **Req 11.5**: Image digest pinning + Falco = FIM for containers347348Full mapping in `references/security-and-compliance.md`.349350## Registry & CI351352### CI pipeline pattern353354- Build with `docker build --check` first, then `buildx` with provenance and SBOM output.355- Scan before deploy, sign by digest, and keep an SBOM artifact even if the registry also stores one.356- Pin CI-side tools and actions to immutable digests, not mutable tags.357358### Docker Model Runner (AI/ML)359360Docker Model Runner (Engine 29.x, Desktop 4.50+) serves AI models via OpenAI/Ollama-compatible APIs:361362```yaml363# Compose integration with Model Runner364services:365 model:366 provider:367 type: model368 options:369 model: ai/llama3.2:3B-Q4_K_M370 agent:371 build: .372 environment:373 OPENAI_BASE_URL: http://model/v1374```375376GPU 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.377378## Production Checklist379380See 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.381382### Deploy-time additions383384- [ ] runc >= 1.4.0 (CVE-2025-31133/52565/52881 patched)385- [ ] BuildKit >= 0.28.1 (CVE-2026-33747/33748 patched)386- [ ] 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)387- [ ] Trivy v0.74.0+ from official releases (v0.69.4-6 COMPROMISED)388- [ ] Images signed with cosign, verified at deploy389- [ ] SBOM generated for every production image390- [ ] Vulnerability scanning in CI (Docker Scout, Grype, or Trivy v0.74.0+)391- [ ] CI tools pinned to SHA256 digests (not mutable tags)392- [ ] Base images rebuilt/updated regularly (weekly minimum)393- [ ] Separate override files for dev/prod394- [ ] Logging config with rotation (`max-size`, `max-file`)395- [ ] `read_only: true` + `no-new-privileges` + `cap_drop: ALL` on production services396397### Compliance (PCI-DSS 4.0)398399- [ ] Containers run as non-root with minimal capabilities (Req 2.2)400- [ ] Read-only root filesystem, one process per container (Req 2.2)401- [ ] Images scanned for vulnerabilities before deployment (Req 6.3)402- [ ] SBOM generated for every CDE image (Req 6.3.2)403- [ ] No hardcoded secrets in images or compose files (Req 8.6.2)404- [ ] Image digests pinned for immutability (Req 5/11.5)405- [ ] Container logs shipped to immutable SIEM (Req 10)406- [ ] Runtime detection in place (Falco/Tetragon) (Req 5.2/5.3)407- [ ] Registry access audit-logged (Req 10.4.1.1)408- [ ] Base images from trusted, verified sources (Req 6.2.1)409410## Reference Files411412- `references/dockerfile-patterns.md` - Dockerfile templates and build patterns413- `references/compose-patterns.md` - Compose patterns and common stack layouts414- `references/security-and-compliance.md` - container hardening, compliance guidance, and safe public custom image publishing415- `references/alternative-runtimes.md` - Podman, Buildah, Skopeo, and related runtime patterns416- `references/target-versions.md` - September 2026 version snapshot for Docker, Compose, BuildKit, containerd, Podman, Buildah, and runc417418## Output Contract419420See `references/output-contract.md` for the full contract.421422- **Skill name:** DOCKER423- **Deliverable bucket:** `audits`424- **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/<YYYY-MM-DD>-<slug>.md`. When invoked to **answer a question, teach a concept, build a new artifact, or generate content**, respond freely without the contract.425- **Severity scale:** `P0 | P1 | P2 | P3 | info` (see shared contract; only used in audit/review mode).426427## Related Skills428429- **kubernetes** - for deploying containers to K8s clusters. Docker builds the image;430 kubernetes deploys it. Dockerfile optimization belongs here; K8s manifests belong there.431- **ci-cd** - for pipeline design that builds and pushes images. Docker skill covers the432 Dockerfile and Compose patterns; ci-cd covers the pipeline stages around them.433- **security-audit** - for auditing container images, scanning for CVEs, and supply chain434 risks. Docker skill covers hardening best practices; security-audit runs the actual audit.435- **ansible** - can manage containers via `community.docker`, but image building and Compose436 design belong here.437- **databases** - for database containers in Docker Compose. Docker skill owns the Compose438 pattern; databases skill owns the engine tuning within the container.439- **git** - for git tags and version control. Docker skill handles container image tagging;440 git handles git tags and release workflows.441442## Rules4434441. **No `:latest` tags in production.** Pin images to a specific version or SHA256 digest.4452. **Multi-stage builds for compiled/transpiled languages.** Build tools do not belong in production images.4463. **Non-root user.** Every production container must run as non-root (numeric UID for K8s compat).4474. **No secrets in layers.** Not in `ENV`, not in `ARG`, not in `COPY`. Use `--mount=type=secret` or runtime injection.4485. **Deps before source.** Copy dependency manifests first, install, then copy source. Layer cache depends on it.4496. **Healthchecks on everything.** Dockerfile `HEALTHCHECK` and Compose `healthcheck:`.4507. **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).4518. **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.4529. **Compose: no `version:` field.** It's deprecated and removed. Just delete it.45310. **Clean apt cache in the same RUN layer.** `apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*` - all one `RUN`.45411. **`.dockerignore` is not optional.** `.git`, `node_modules`, `.env`, secrets, test fixtures, docs - all excluded.45512. **Resource limits on production containers.** Memory and CPU limits prevent noisy neighbors and OOM cascading.45613. **Run the AI self-check.** Every generated Dockerfile/Compose gets verified against the checklist above before returning.
Run npx skillmds@latest add iuliandita/docker in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
· Write/review Dockerfiles, Compose, OCI/Podman/BuildKit builds, signing, hardening. Triggers: 'docker', 'dockerfile', 'podman', 'buildkit', 'buildah', 'skopeo', 'containerd'. Not for K8s manifests (use kubernetes). It is listed under DevOps & Infra on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: FAIL, Skill Scanner: PASS. Capability flags: makes network calls, reads secrets. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free. This skill is licensed under MIT.
iuliandita (@iuliandita) published this skill. Their other Agent Skills are listed on their SkillMD profile.