[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EHV1BE83V75MTAP99ZTVFX":3,"skill-same:01M7EHV1BE83V75MTAP99ZTVFX":75},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":38,"repositoryHtmlUrl":39,"repositoryHomepageUrl":6,"ownerHtmlUrl":40,"ownerBlogUrl":6,"ownerDescription":41,"updatedAt":42,"install":43,"resources":56},"01M7EHV1BE83V75MTAP99ZTVFX","docker",null,"Use when authoring or auditing a Dockerfile, shrinking a bloated image, hardening a container that runs as root, picking a base image, or wiring a Compose dev loop with hot reload. NOT CI builds or deploy-to-host (that is `deployment`), NOT k8s autoscaling (that is `scaling`), NOT app-level injection or secrets-in-code (that is `secure-coding`).","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: docker\ndescription: \"Use when authoring or auditing a Dockerfile, shrinking a bloated image, hardening a container that runs as root, picking a base image, or wiring a Compose dev loop with hot reload. NOT CI builds or deploy-to-host (that is `deployment`), NOT k8s autoscaling (that is `scaling`), NOT app-level injection or secrets-in-code (that is `secure-coding`).\"\ntags: [docker, containers, dockerfile, compose, image-security]\nrecommends: [deployment, secure-coding, scaling, github-actions]\norigin: risco\n---\n\n# docker — container-craft\n\nYou own one question, deeply: **how do I turn this app into a small, secure, fast-building\nimage — and run a frictionless local stack with Compose?** Your artifacts are the `Dockerfile`,\nthe `.dockerignore`, and the `compose.yaml`: their layers, their attack surface, their build\ncache, their dev loop. You do not touch what happens after the image is built.\n\n```text\nsource  →  Dockerfile (multi-stage, cache mounts)  →  small + scanned image  +  compose.yaml (dev loop)\n                                                            └──────────────┬──────────────┘\n                                                    hand off to ..\u002Fdeployment\u002FSKILL.md\n```\n\nThe hand-off is sharp: **the moment you have a green, scanned image and a working\n`compose.yaml`, you are done.** Everything downstream is `..\u002Fdeployment\u002FSKILL.md` — it already\nreferences Dockerfiles and leans on you for the image internals.\n\n## When NOT to use — and who owns it instead\n\n| You're asked for… | Owner | Why it's not you |\n|---|---|---|\n| CI build, registry push, deploy to host, rollback | `..\u002Fdeployment\u002FSKILL.md` | You build + harden the image; it moves the image through CI to prod |\n| k8s manifests, HPA autoscaling, ingress | `scaling` | Orchestration above a single image |\n| App SQL injection, secrets in source, dep CVE triage | `..\u002Fsecure-coding\u002FSKILL.md` | You cover only *image\u002Fcontainer* hardening |\n| Install\u002Foperate a self-hosted PaaS | `..\u002Fcoolify\u002FSKILL.md` | Host operation, not the image |\n| Containerless PaaS deploy mechanics | `..\u002Frailway\u002FSKILL.md`, `..\u002Ffly-io\u002FSKILL.md` | Platform deploy, not the Dockerfile |\n\n## Pick a base image (2026 reality)\n\n| Base | Size | CVE \u002F patch velocity | Debuggable? | Wins when |\n|---|---|---|---|---|\n| `*-slim` (e.g. `bookworm-slim`) | ~30–80 MB | moderate, glibc | yes (shell, apt) | pragmatic default, native deps \u002F Python wheels |\n| `distroless` (`gcr.io\u002Fdistroless\u002F*`) | ~2–25 MB | convenient but **patches slower** | no shell | static\u002Fcompiled runtimes, want minimal surface |\n| **Chainguard \u002F Wolfi** | tiny, glibc | **lowest live CVE count**, SLSA L3 attestations | minimal | security-first; real scans found high-sev CVEs where the Chainguard equivalent had zero |\n| `alpine` | ~5 MB, musl | small surface | yes (apk) | tiny static services — **but musl breaks many Python wheels \u002F native deps** |\n| `scratch` | 0 | nothing to patch | no | a fully static binary (Go), nothing else |\n\nRule of thumb: glibc app with native deps → `*-slim` or Wolfi. Static Go binary → `scratch` or\n`distroless\u002Fstatic`. Security mandate → Chainguard. Reach for `alpine` only when you've confirmed\nyour wheels\u002Fnative libs build against musl. Per-language tag maps, multi-stage templates for the\nstacks not shown below (Rust, JVM `jlink`, static SPA → nginx) and multi-arch buildx live in\n[references\u002Fbase-images-and-stages.md](references\u002Fbase-images-and-stages.md).\n\n## Multi-stage skeletons\n\n**Node — `npm ci` with a cache mount → distroless nonroot.** Bad: single-stage `node:20` ≈ 1.1 GB.\nGood: this ≈ 180 MB. Tags track Node 24 (the active LTS as of mid-2026); Node 22 is in Maintenance\nLTS, so swap `24`→`22` only when you deliberately want the conservative maintenance line.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM node:24-bookworm-slim AS build\nWORKDIR \u002Fapp\nCOPY package.json package-lock.json .\u002F\nRUN --mount=type=cache,target=\u002Froot\u002F.npm npm ci\nCOPY . .\nRUN npm run build && npm prune --omit=dev\n\nFROM gcr.io\u002Fdistroless\u002Fnodejs24-debian13:nonroot\nWORKDIR \u002Fapp\nCOPY --from=build \u002Fapp\u002Fnode_modules .\u002Fnode_modules\nCOPY --from=build \u002Fapp\u002Fdist .\u002Fdist\nUSER nonroot\nEXPOSE 3000\nHEALTHCHECK --interval=30s --timeout=3s CMD [\"node\", \"dist\u002Fhealthcheck.js\"]\nCMD [\"dist\u002Fserver.js\"]\n```\n\n**Python — `uv` into a venv → slim, non-root.** Bad: `python:3.12` + `pip` ≈ 1 GB. Good: ≈ 130 MB.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM python:3.13-slim-bookworm AS build\nCOPY --from=ghcr.io\u002Fastral-sh\u002Fuv:latest \u002Fuv \u002Fusr\u002Flocal\u002Fbin\u002Fuv\nWORKDIR \u002Fapp\nENV UV_PROJECT_ENVIRONMENT=\u002Fopt\u002Fvenv\nCOPY pyproject.toml uv.lock .\u002F\nRUN --mount=type=cache,target=\u002Froot\u002F.cache\u002Fuv uv sync --frozen --no-dev\n\nFROM python:3.13-slim-bookworm\nRUN useradd --create-home --uid 10001 app\nCOPY --from=build --chown=app:app \u002Fopt\u002Fvenv \u002Fopt\u002Fvenv\nCOPY --chown=app:app . \u002Fapp\nWORKDIR \u002Fapp\nENV PATH=\"\u002Fopt\u002Fvenv\u002Fbin:$PATH\"\nUSER app\nEXPOSE 8000\nHEALTHCHECK CMD [\"python\", \"-c\", \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http:\u002F\u002Flocalhost:8000\u002Fhealth').status==200 else 1)\"]\nCMD [\"uvicorn\", \"app.main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8000\"]\n```\n\n**Go — static binary → `scratch`.** Bad: `golang:1.26` ≈ 900 MB. Good: ≈ 12 MB. Pin a\nsupported toolchain: Go maintains only the latest two minors (1.26\u002F1.25 as of mid-2026), so a\n`golang:1.23` build image is two minors past EOL and no longer gets security patches.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM golang:1.26-bookworm AS build\nWORKDIR \u002Fsrc\nCOPY go.mod go.sum .\u002F\nRUN --mount=type=cache,target=\u002Fgo\u002Fpkg\u002Fmod go mod download\nCOPY . .\nRUN --mount=type=cache,target=\u002Froot\u002F.cache\u002Fgo-build \\\n    CGO_ENABLED=0 go build -trimpath -ldflags=\"-s -w\" -o \u002Fapp .\u002Fcmd\u002Fserver\n\nFROM scratch\nCOPY --from=build \u002Fetc\u002Fssl\u002Fcerts\u002Fca-certificates.crt \u002Fetc\u002Fssl\u002Fcerts\u002F\nCOPY --from=build \u002Fapp \u002Fapp\nUSER 10001:10001\nEXPOSE 8080\nENTRYPOINT [\"\u002Fapp\"]\n```\n\nThe cache-mount `target` differs per ecosystem: `\u002Froot\u002F.npm`, `\u002Froot\u002F.cache\u002Fuv` (or\n`\u002Froot\u002F.cache\u002Fpip`), `\u002Fgo\u002Fpkg\u002Fmod`. The cache persists across builds without bloating any layer.\n\n## `.dockerignore` — load-bearing, not optional\n\nWithout it the entire context (including `.git`, `node_modules`, `.env`) ships to the daemon: it\nslows the build and can bake secrets into a layer via `COPY .`.\n\n```gitignore\n.git\n.gitignore\nnode_modules\ndist\n.env\n.env.*\n*.log\n.venv\n__pycache__\nDockerfile\n.dockerignore\nREADME.md\n```\n\nMirror `.gitignore`, then add build outputs and the Dockerfile itself.\n\n## Harden the runtime\n\nNon-root in the image (already shown above): create a user, `COPY --chown`, `USER`. Then lock the\nruntime down where the container actually runs:\n\n```bash\ndocker run \\\n  --read-only --tmpfs \u002Ftmp \\\n  --security-opt=no-new-privileges \\\n  --cap-drop=ALL \\\n  myimage:1.4.0\n```\n\n`--read-only` rootfs + `--tmpfs \u002Ftmp` for scratch space; `no-new-privileges` blocks setuid\nescalation; `--cap-drop=ALL` then add back only what you truly need (`--cap-add=NET_BIND_SERVICE`\nto bind port \u003C 1024).\n\n**Build secrets — never `ARG`\u002F`ENV`.** An `ARG TOKEN` lands in the image history and any\n`ENV SECRET=...` persists in a layer. Use a BuildKit secret mount; it is never written to a layer:\n\n```dockerfile\n# Bad — leaks into image history:  ARG NPM_TOKEN\n# Good:\nRUN --mount=type=secret,id=npm_token \\\n    NPM_TOKEN=\"$(cat \u002Frun\u002Fsecrets\u002Fnpm_token)\" npm ci\n```\n\n```bash\ndocker build --secret id=npm_token,env=NPM_TOKEN .\n```\n\n## Compose for dev\n\nCanonical filename is `compose.yaml`; **omit the obsolete `version:` key**; use `docker compose`\n(v2 subcommand), never the standalone `docker-compose` v1. One concern per container — the app, the\ndatabase and the seed job are separate services. `develop.watch` is GA since Compose 2.22.0 and\ngives you a tight dev loop.\n\n```yaml\nservices:\n  api:\n    build: .\n    ports: [\"8000:8000\"]\n    depends_on:\n      db:\n        condition: service_healthy\n    develop:\n      watch:\n        - action: sync          # hot-reload: copy changed files into the container\n          path: .\u002Fsrc\n          target: \u002Fapp\u002Fsrc\n        - action: rebuild       # lockfile \u002F compiled langs: rebuild the image\n          path: .\u002Fuv.lock\n        - action: sync+restart  # config change: sync then restart the process\n          path: .\u002Fconfig.yaml\n          target: \u002Fapp\u002Fconfig.yaml\n  db:\n    image: postgres:17-bookworm\n    environment:\n      POSTGRES_PASSWORD: dev\n    volumes: [\"pgdata:\u002Fvar\u002Flib\u002Fpostgresql\u002Fdata\"]\n    healthcheck:\n      test: [\"CMD-SHELL\", \"pg_isready -U postgres\"]\n      interval: 5s\n      timeout: 3s\n      retries: 5\n  seed:\n    profiles: [\"tools\"]         # only runs with: docker compose --profile tools up\n    build: .\n    command: [\"python\", \"-m\", \"app.seed\"]\n\nvolumes:\n  pgdata:\n```\n\nRun the dev loop with `docker compose watch` (or `docker compose up --watch`). Fuller patterns —\nwatch-per-stack, multi-service healthcheck graphs, override files, `env_file` vs `secrets`, and\nwhen to graduate to `deployment`\u002F`scaling` — are in\n[references\u002Fcompose-recipes.md](references\u002Fcompose-recipes.md).\n\n## Verify the image\n\nThese are exactly what `scripts\u002Fverify.sh` automates (it skips a tool gracefully if absent):\n\n- `hadolint Dockerfile` — static lint of the Dockerfile (no error-level findings).\n- `docker compose config -q` — the `compose.yaml` parses and resolves.\n- `trivy image myimage:1.4.0` — CVE + misconfig + secret scan of the built image.\n- `trivy config .` — scan the Dockerfile\u002Fcompose for misconfiguration without a build.\n- `dockle myimage:1.4.0` — CIS-style image hygiene.\n- size check — assert the final image is under your threshold (`docker image inspect -f '{{.Size}}'`).\n\n## Anti-patterns\n\n| Bad | Good | Why |\n|---|---|---|\n| `FROM node:latest` | `FROM node:24-bookworm-slim`, or pin a digest | `:latest` drifts under you; builds + scans become non-reproducible |\n| runs as root (no `USER`) | `USER nonroot` \u002F `USER 10001` | PID 1 defaults to root (UID 0), so a container escape == host compromise |\n| `ARG TOKEN` \u002F `ENV SECRET=` | `RUN --mount=type=secret,...` | ARG\u002FENV persist in image history & layers |\n| `COPY . .` then `RUN npm ci` | copy lockfile → install → copy source | source edits bust the dep cache layer every build |\n| single `FROM`, ship the SDK | multi-stage, copy only the artifact | runtime carries compilers & dev CVE surface |\n| `apt-get install x` | `apt-get install --no-install-recommends x && rm -rf \u002Fvar\u002Flib\u002Fapt\u002Flists\u002F*` | recommends + apt lists bloat the layer |\n| no `.dockerignore` | mirror `.gitignore` + build outputs | whole context ships; `.env`\u002F`.git` can leak |\n| `version: \"3.8\"` \u002F `docker-compose` v1 | omit `version:`; `docker compose` v2 | the key is obsolete; v1 is EOL |\n| `CMD npm start` (shell form) | `CMD [\"node\", \"server.js\"]` (exec) | shell form wraps the process in `\u002Fbin\u002Fsh -c`, which swallows `SIGTERM` — no graceful shutdown |\n| no `HEALTHCHECK` | `HEALTHCHECK CMD [...]` | nothing for Compose\u002Forchestrators to gate readiness on (`condition: service_healthy`) |\n","# docker — container-craft\n\nYou own one question, deeply: **how do I turn this app into a small, secure, fast-building\nimage — and run a frictionless local stack with Compose?** Your artifacts are the `Dockerfile`,\nthe `.dockerignore`, and the `compose.yaml`: their layers, their attack surface, their build\ncache, their dev loop. You do not touch what happens after the image is built.\n\n```text\nsource  →  Dockerfile (multi-stage, cache mounts)  →  small + scanned image  +  compose.yaml (dev loop)\n                                                            └──────────────┬──────────────┘\n                                                    hand off to ..\u002Fdeployment\u002FSKILL.md\n```\n\nThe hand-off is sharp: **the moment you have a green, scanned image and a working\n`compose.yaml`, you are done.** Everything downstream is `..\u002Fdeployment\u002FSKILL.md` — it already\nreferences Dockerfiles and leans on you for the image internals.\n\n## When NOT to use — and who owns it instead\n\n| You're asked for… | Owner | Why it's not you |\n|---|---|---|\n| CI build, registry push, deploy to host, rollback | `..\u002Fdeployment\u002FSKILL.md` | You build + harden the image; it moves the image through CI to prod |\n| k8s manifests, HPA autoscaling, ingress | `scaling` | Orchestration above a single image |\n| App SQL injection, secrets in source, dep CVE triage | `..\u002Fsecure-coding\u002FSKILL.md` | You cover only *image\u002Fcontainer* hardening |\n| Install\u002Foperate a self-hosted PaaS | `..\u002Fcoolify\u002FSKILL.md` | Host operation, not the image |\n| Containerless PaaS deploy mechanics | `..\u002Frailway\u002FSKILL.md`, `..\u002Ffly-io\u002FSKILL.md` | Platform deploy, not the Dockerfile |\n\n## Pick a base image (2026 reality)\n\n| Base | Size | CVE \u002F patch velocity | Debuggable? | Wins when |\n|---|---|---|---|---|\n| `*-slim` (e.g. `bookworm-slim`) | ~30–80 MB | moderate, glibc | yes (shell, apt) | pragmatic default, native deps \u002F Python wheels |\n| `distroless` (`gcr.io\u002Fdistroless\u002F*`) | ~2–25 MB | convenient but **patches slower** | no shell | static\u002Fcompiled runtimes, want minimal surface |\n| **Chainguard \u002F Wolfi** | tiny, glibc | **lowest live CVE count**, SLSA L3 attestations | minimal | security-first; real scans found high-sev CVEs where the Chainguard equivalent had zero |\n| `alpine` | ~5 MB, musl | small surface | yes (apk) | tiny static services — **but musl breaks many Python wheels \u002F native deps** |\n| `scratch` | 0 | nothing to patch | no | a fully static binary (Go), nothing else |\n\nRule of thumb: glibc app with native deps → `*-slim` or Wolfi. Static Go binary → `scratch` or\n`distroless\u002Fstatic`. Security mandate → Chainguard. Reach for `alpine` only when you've confirmed\nyour wheels\u002Fnative libs build against musl. Per-language tag maps, multi-stage templates for the\nstacks not shown below (Rust, JVM `jlink`, static SPA → nginx) and multi-arch buildx live in\n[references\u002Fbase-images-and-stages.md](references\u002Fbase-images-and-stages.md).\n\n## Multi-stage skeletons\n\n**Node — `npm ci` with a cache mount → distroless nonroot.** Bad: single-stage `node:20` ≈ 1.1 GB.\nGood: this ≈ 180 MB. Tags track Node 24 (the active LTS as of mid-2026); Node 22 is in Maintenance\nLTS, so swap `24`→`22` only when you deliberately want the conservative maintenance line.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM node:24-bookworm-slim AS build\nWORKDIR \u002Fapp\nCOPY package.json package-lock.json .\u002F\nRUN --mount=type=cache,target=\u002Froot\u002F.npm npm ci\nCOPY . .\nRUN npm run build && npm prune --omit=dev\n\nFROM gcr.io\u002Fdistroless\u002Fnodejs24-debian13:nonroot\nWORKDIR \u002Fapp\nCOPY --from=build \u002Fapp\u002Fnode_modules .\u002Fnode_modules\nCOPY --from=build \u002Fapp\u002Fdist .\u002Fdist\nUSER nonroot\nEXPOSE 3000\nHEALTHCHECK --interval=30s --timeout=3s CMD [\"node\", \"dist\u002Fhealthcheck.js\"]\nCMD [\"dist\u002Fserver.js\"]\n```\n\n**Python — `uv` into a venv → slim, non-root.** Bad: `python:3.12` + `pip` ≈ 1 GB. Good: ≈ 130 MB.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM python:3.13-slim-bookworm AS build\nCOPY --from=ghcr.io\u002Fastral-sh\u002Fuv:latest \u002Fuv \u002Fusr\u002Flocal\u002Fbin\u002Fuv\nWORKDIR \u002Fapp\nENV UV_PROJECT_ENVIRONMENT=\u002Fopt\u002Fvenv\nCOPY pyproject.toml uv.lock .\u002F\nRUN --mount=type=cache,target=\u002Froot\u002F.cache\u002Fuv uv sync --frozen --no-dev\n\nFROM python:3.13-slim-bookworm\nRUN useradd --create-home --uid 10001 app\nCOPY --from=build --chown=app:app \u002Fopt\u002Fvenv \u002Fopt\u002Fvenv\nCOPY --chown=app:app . \u002Fapp\nWORKDIR \u002Fapp\nENV PATH=\"\u002Fopt\u002Fvenv\u002Fbin:$PATH\"\nUSER app\nEXPOSE 8000\nHEALTHCHECK CMD [\"python\", \"-c\", \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http:\u002F\u002Flocalhost:8000\u002Fhealth').status==200 else 1)\"]\nCMD [\"uvicorn\", \"app.main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8000\"]\n```\n\n**Go — static binary → `scratch`.** Bad: `golang:1.26` ≈ 900 MB. Good: ≈ 12 MB. Pin a\nsupported toolchain: Go maintains only the latest two minors (1.26\u002F1.25 as of mid-2026), so a\n`golang:1.23` build image is two minors past EOL and no longer gets security patches.\n\n```dockerfile\n# syntax=docker\u002Fdockerfile:1\nFROM golang:1.26-bookworm AS build\nWORKDIR \u002Fsrc\nCOPY go.mod go.sum .\u002F\nRUN --mount=type=cache,target=\u002Fgo\u002Fpkg\u002Fmod go mod download\nCOPY . .\nRUN --mount=type=cache,target=\u002Froot\u002F.cache\u002Fgo-build \\\n    CGO_ENABLED=0 go build -trimpath -ldflags=\"-s -w\" -o \u002Fapp .\u002Fcmd\u002Fserver\n\nFROM scratch\nCOPY --from=build \u002Fetc\u002Fssl\u002Fcerts\u002Fca-certificates.crt \u002Fetc\u002Fssl\u002Fcerts\u002F\nCOPY --from=build \u002Fapp \u002Fapp\nUSER 10001:10001\nEXPOSE 8080\nENTRYPOINT [\"\u002Fapp\"]\n```\n\nThe cache-mount `target` differs per ecosystem: `\u002Froot\u002F.npm`, `\u002Froot\u002F.cache\u002Fuv` (or\n`\u002Froot\u002F.cache\u002Fpip`), `\u002Fgo\u002Fpkg\u002Fmod`. The cache persists across builds without bloating any layer.\n\n## `.dockerignore` — load-bearing, not optional\n\nWithout it the entire context (including `.git`, `node_modules`, `.env`) ships to the daemon: it\nslows the build and can bake secrets into a layer via `COPY .`.\n\n```gitignore\n.git\n.gitignore\nnode_modules\ndist\n.env\n.env.*\n*.log\n.venv\n__pycache__\nDockerfile\n.dockerignore\nREADME.md\n```\n\nMirror `.gitignore`, then add build outputs and the Dockerfile itself.\n\n## Harden the runtime\n\nNon-root in the image (already shown above): create a user, `COPY --chown`, `USER`. Then lock the\nruntime down where the container actually runs:\n\n```bash\ndocker run \\\n  --read-only --tmpfs \u002Ftmp \\\n  --security-opt=no-new-privileges \\\n  --cap-drop=ALL \\\n  myimage:1.4.0\n```\n\n`--read-only` rootfs + `--tmpfs \u002Ftmp` for scratch space; `no-new-privileges` blocks setuid\nescalation; `--cap-drop=ALL` then add back only what you truly need (`--cap-add=NET_BIND_SERVICE`\nto bind port \u003C 1024).\n\n**Build secrets — never `ARG`\u002F`ENV`.** An `ARG TOKEN` lands in the image history and any\n`ENV SECRET=...` persists in a layer. Use a BuildKit secret mount; it is never written to a layer:\n\n```dockerfile\n# Bad — leaks into image history:  ARG NPM_TOKEN\n# Good:\nRUN --mount=type=secret,id=npm_token \\\n    NPM_TOKEN=\"$(cat \u002Frun\u002Fsecrets\u002Fnpm_token)\" npm ci\n```\n\n```bash\ndocker build --secret id=npm_token,env=NPM_TOKEN .\n```\n\n## Compose for dev\n\nCanonical filename is `compose.yaml`; **omit the obsolete `version:` key**; use `docker compose`\n(v2 subcommand), never the standalone `docker-compose` v1. One concern per container — the app, the\ndatabase and the seed job are separate services. `develop.watch` is GA since Compose 2.22.0 and\ngives you a tight dev loop.\n\n```yaml\nservices:\n  api:\n    build: .\n    ports: [\"8000:8000\"]\n    depends_on:\n      db:\n        condition: service_healthy\n    develop:\n      watch:\n        - action: sync          # hot-reload: copy changed files into the container\n          path: .\u002Fsrc\n          target: \u002Fapp\u002Fsrc\n        - action: rebuild       # lockfile \u002F compiled langs: rebuild the image\n          path: .\u002Fuv.lock\n        - action: sync+restart  # config change: sync then restart the process\n          path: .\u002Fconfig.yaml\n          target: \u002Fapp\u002Fconfig.yaml\n  db:\n    image: postgres:17-bookworm\n    environment:\n      POSTGRES_PASSWORD: dev\n    volumes: [\"pgdata:\u002Fvar\u002Flib\u002Fpostgresql\u002Fdata\"]\n    healthcheck:\n      test: [\"CMD-SHELL\", \"pg_isready -U postgres\"]\n      interval: 5s\n      timeout: 3s\n      retries: 5\n  seed:\n    profiles: [\"tools\"]         # only runs with: docker compose --profile tools up\n    build: .\n    command: [\"python\", \"-m\", \"app.seed\"]\n\nvolumes:\n  pgdata:\n```\n\nRun the dev loop with `docker compose watch` (or `docker compose up --watch`). Fuller patterns —\nwatch-per-stack, multi-service healthcheck graphs, override files, `env_file` vs `secrets`, and\nwhen to graduate to `deployment`\u002F`scaling` — are in\n[references\u002Fcompose-recipes.md](references\u002Fcompose-recipes.md).\n\n## Verify the image\n\nThese are exactly what `scripts\u002Fverify.sh` automates (it skips a tool gracefully if absent):\n\n- `hadolint Dockerfile` — static lint of the Dockerfile (no error-level findings).\n- `docker compose config -q` — the `compose.yaml` parses and resolves.\n- `trivy image myimage:1.4.0` — CVE + misconfig + secret scan of the built image.\n- `trivy config .` — scan the Dockerfile\u002Fcompose for misconfiguration without a build.\n- `dockle myimage:1.4.0` — CIS-style image hygiene.\n- size check — assert the final image is under your threshold (`docker image inspect -f '{{.Size}}'`).\n\n## Anti-patterns\n\n| Bad | Good | Why |\n|---|---|---|\n| `FROM node:latest` | `FROM node:24-bookworm-slim`, or pin a digest | `:latest` drifts under you; builds + scans become non-reproducible |\n| runs as root (no `USER`) | `USER nonroot` \u002F `USER 10001` | PID 1 defaults to root (UID 0), so a container escape == host compromise |\n| `ARG TOKEN` \u002F `ENV SECRET=` | `RUN --mount=type=secret,...` | ARG\u002FENV persist in image history & layers |\n| `COPY . .` then `RUN npm ci` | copy lockfile → install → copy source | source edits bust the dep cache layer every build |\n| single `FROM`, ship the SDK | multi-stage, copy only the artifact | runtime carries compilers & dev CVE surface |\n| `apt-get install x` | `apt-get install --no-install-recommends x && rm -rf \u002Fvar\u002Flib\u002Fapt\u002Flists\u002F*` | recommends + apt lists bloat the layer |\n| no `.dockerignore` | mirror `.gitignore` + build outputs | whole context ships; `.env`\u002F`.git` can leak |\n| `version: \"3.8\"` \u002F `docker-compose` v1 | omit `version:`; `docker compose` v2 | the key is obsolete; v1 is EOL |\n| `CMD npm start` (shell form) | `CMD [\"node\", \"server.js\"]` (exec) | shell form wraps the process in `\u002Fbin\u002Fsh -c`, which swallows `SIGTERM` — no graceful shutdown |\n| no `HEALTHCHECK` | `HEALTHCHECK CMD [...]` | nothing for Compose\u002Forchestrators to gate readiness on (`condition: service_healthy`) |\n",{"name":5,"tags":24,"origin":29,"recommends":30,"description":7},[5,25,26,27,28],"containers","dockerfile","compose","image-security","risco",[31,32,33,34],"deployment","secure-coding","scaling","github-actions","main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","04-安全渗透\u002Fdocker",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill docker",{"tool":49,"command":50},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill docker",{"tool":52,"command":53},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill docker","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002FSKILL.md",true,[57,63,67,71],{"path":58,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":61,"sourceHtmlUrl":62},"evals\u002Fcases.yaml","REFERENCE","参考文档",2406,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002Fevals\u002Fcases.yaml",{"path":64,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":65,"sourceHtmlUrl":66},"evals\u002FREADME.md",788,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002Fevals\u002FREADME.md",{"path":68,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Fbase-images-and-stages.md",3952,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002Freferences\u002Fbase-images-and-stages.md",{"path":72,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fcompose-recipes.md",3397,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdocker\u002Freferences\u002Fcompose-recipes.md",[76,84,89,96,103,110],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":83},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":85,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":83},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":83},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":83},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":83},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":83},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]