docker-agent-config
Use this skill when creating or editing an agent.yaml (or .yml/.hcl) configuration file for Docker Agent (cagent), including…
Use this skill when writing, reviewing, or optimizing Dockerfiles, even if the user just says their image is too large, their build is slow, or they need to harden a container for production. Covers multi-stage builds, layer caching, .dockerignore, non-root users, and image size
$ npx -y skills add docker/skills --skill docker-build-strategies --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/docker-build-strategiesContext preview
The summary Claude sees to decide when to auto-load this skill.
Use this skill when writing, reviewing, or optimizing Dockerfiles, even if the user just says their image is too large, their build is slow, or they need to harden a container for production. Covers multi-stage builds, layer caching, .dockerignore, non-root users, and image size
name: docker-build-strategies description: Use this skill when writing, reviewing, or optimizing Dockerfiles, even if the user just says their image is too large, their build is slow, or they need to harden a container for production. Covers multi-stage builds, layer caching, .dockerignore, non-root users, and image size optimization. license: Apache-2.0 compatibility: Requires Docker 23.0+ (BuildKit default). On Docker 20.10–22.x, set DOCKER_BUILDKIT=1 before building.
This skill provides rules and patterns for writing and reviewing production-quality Dockerfiles. Apply it when the main task is image-build quality: multi-stage builds, cache behavior, non-root execution, build context hygiene, and runtime image size.
Activate this skill when:
Do not use this skill when:
Use multi-stage builds when the project has a build step or when build-time dependencies differ from runtime. Separate build-time dependencies from the runtime image.
1. Name every stage explicitly (`FROM ... AS build`, `FROM ... AS runtime`). 2. Use the smallest appropriate base for the runtime stage: `distroless`, `alpine`, or `slim` variants. 3. Copy only the final artifact into the runtime stage with `COPY --from=build`. 4. Use `COPY --link` when copying from a prior stage or adding static files — it improves cache reuse by making the COPY independent of previous layers.
See `references/multi-stage-builds.md` for language-specific patterns (Go, Node, Python, Java).
Order Dockerfile instructions from least-frequently-changed to most-frequently-changed.
1. Place dependency manifests (`package.json`, `go.mod`, `requirements.txt`) and install steps before copying application source code. Bind-mount the manifest into the install step instead of `COPY`-ing it, so it never enters a layer: `RUN --mount=type=bind,source=package.json,target=package.json --mount=type=bind,source=package-lock.json,target=package-lock.json npm ci`. This is safe for install commands that only read the manifest (`npm ci`, `pip install -r`, `go mod download`); if a step also needs to write the manifest back into the image, `COPY` it instead. 2. Use BuildKit cache mounts for package manager caches:
3. Pin base image tags to a specific version or digest — never use `latest` in production. 4. Combine related `RUN` commands with `&&` to reduce layer count, but keep logically distinct steps separate for cache granularity.
See `references/layer-caching.md` for detailed cache invalidation rules and cache mount patterns.
Never bake credentials into the image. Use BuildKit secrets and SSH mounts so credentials are available only during the specific `RUN` step that needs them, and never persist in any layer or `docker history` output.
1. **Do NOT** pass credentials through `ARG` or `ENV`. Both end up in the image layers and are inspectable via `docker history`. 2. **Do NOT** `COPY` credential files into the build context: `.npmrc`, `.pypirc`, `.netrc`, `pip.conf`, Maven `settings.xml`, `.env`, cloud credentials (`~/.aws/credentials`, `~/.config/gcloud/`, service-account JSON files, `~/.azure/`), secret-manager tokens (`~/.vault-token`), package-registry tokens (`~/.cargo/credentials.toml`), TLS keys (`*.pem`, `*.p12`), `kubeconfig`, SSH keys (`id_rsa`, `id_dsa`, `id_ed25519`, `id_ecdsa`). Even when the final stage does not copy them forward, they live in intermediate layers and the build cache. 3. **Do NOT** echo, write, or expand the secret value inside a `RUN` command in a way that persists it to a layer or emits it to build logs. Access the secret file (e.g., `/run/secrets/<id>`, or directly via the mount `target=`) — never `echo "$(cat /run/secrets/X)"`, never substitute it into a shell argument that will be logged with `--progress=plain`. 4. **Use `RUN --mount=type=secret`** for package manager registry credentials:
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
--mount=type=cache,target=/root/.npm \
npm ci --omit=devThe secret is available only inside that `RUN`, never written to a layer. Use `required=true` when the build will always need the credential (e.g., all packages come from a private registry, so missing the secret should fail the build immediately); use `required=false` only when the secret is optional (the build can succeed with public packages alone). 5. **Use `RUN --mount=type=ssh`** for fetching private Git repositories or modules. The build container has no `known_hosts` by default
Docker-authored knowledge skills that improve AI coding agent output for Docker-related tasks. Skills are authored once as portable SKILL.md directories and discovered automatically by any compliant agent through standard skill paths.
Use this skill when creating or editing an agent.yaml (or .yml/.hcl) configuration file for Docker Agent (cagent), including…
Use this skill when exposing a Docker Agent as a server (MCP, HTTP API, A2A, ACP, or OpenAI-compatible chat), distributing an…
Use this skill when running a Docker Agent with `docker agent run`, choosing a safety/approval mode, using the `--sandbox`…
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire…
Use this skill before running, or recommending, any Docker command that deletes, wipes, resets, or otherwise irreversibly changes…
Use this skill when setting up, initializing, or Dockerizing a project, even if the user doesn't explicitly mention Docker but…