Write or fix a container image build — multi-stage Dockerfile, pinned minimal base, non-root user, no secrets in layers, SBOM — built locally, never pushed. Use when a Dockerfile or compose file changes, or an image is large, slow, or fails a scan.
¿Qué es container-build?
container-build is a Claude Code agent skill that write or fix a container image build — multi-stage Dockerfile, pinned minimal base, non-root user, no secrets in layers, SBOM — built locally, never pushed. Use when a Dockerfile or compose file changes, or an image is large, slow, or fails a scan.
Pin every image reference by exact version and digest (<image>:<x.y.z>@sha256:<digest>): each FROM stage, COPY --from=<image>, the # syntax= frontend, and compose image:. Never latest, a bare major tag (node:22), or no tag. "Image tags are mutable, meaning a publisher can update a tag to point to a new image"; with a digest, "you're opting out of automated security fixes" unless a bot moves the pin (docs.docker.com, "Building best practices", accessed 2026-11-28). So every pin is renovated (Pinning and renovation, below).
No secret in any layer, build argument, ENV, or label: build arguments and environment variables persist in the image. Use RUN --mount=type=secret,id=<id> (mounted at /run/secrets/<id>) and RUN --mount=type=ssh (docs.docker.com, "Build secrets", accessed 2026-11-28). --provenance=mode=max records build-argument values; secret mounts are never included (docs.docker.com, "Provenance attestations", accessed 2026-11-28).
Run as a numeric non-root user (USER 10001:10001, example values) so Kubernetes runAsNonRoot can verify it.
The final stage holds only the runtime and the artifact: no compilers, package managers, tests, or source.
Build, run, and scan locally only. Pushing, tagging releases, and signing in the registry are pipeline or orchestrator actions.
Dockerfile checks
Area
Do
Avoid
Base
Official, verified, minimal, or distroless image; exact version plus digest; new bases evaluated with dependency-evaluation
latest, major or minor tags the publisher moves, unknown publishers
Stages
Build stage with the toolchain; final stage copies artifacts with COPY --from
Shipping the toolchain
Context
.dockerignore excluding .git, .env*, keys, local build output, and test data
Sending secrets and history to the builder
Layer order
Copy lockfiles, install dependencies, then copy sources; apt-get update and install in one RUN; clean package caches in that layer
apt-get update in its own layer; ADD of a remote URL without a checksum
Packages
Exact versions where the ecosystem allows; no recommended extras
Floating versions
Filesystem
Application files owned by root and read-only to the app user; writable paths only where needed
chmod 777; writable application code
Process
Exec-form ENTRYPOINT and CMD; the process handles SIGTERM; EXPOSE the ports used
Shell form that swallows SIGTERM
Health
HEALTHCHECK for compose and other runtimes that use it; on Kubernetes rely on liveness, readiness, and startup probes instead (kubernetes-manifests); distroless images need a probe binary
The most specific version tag the publisher offers (for example <x.y.z>-<variant><os-version>), not a major or latest alias
Find the digest
docker buildx imagetools inspect <image>:<tag> reads the registry and prints Digest: sha256:…; --format "{{json .Manifest}}" gives it as the top-level digest field (docs.docker.com, "docker buildx imagetools inspect", accessed 2026-11-28). For a multi-platform image this is the index digest; pin it, not a per-platform digest, so every platform resolves (OpenSSF Scorecard Pinned-Dependencies: "pin to the manifest list hash", github.com/ossf/scorecard docs/checks.md, accessed 2026-11-28)
Write the pin
FROM <image>:<x.y.z>@sha256:<digest>; keep the tag for readers and bots, because the digest alone decides what is pulled
Syntax directive
# syntax=docker/dockerfile:1 pulls the latest stable 1.x frontend at build time (docs.docker.com, "Dockerfile reference", accessed 2026-11-28): pin it as docker/dockerfile:<x.y.z>@sha256:<digest>, or omit it so "BuildKit uses a bundled version of the Dockerfile frontend"
Renovate
pinDigests defaults to false; the docker:pinDigests preset turns it on for Docker images. Renovate keeps the tag next to the digest and raises a pull request whenever the image behind that tag changes; it covers Dockerfiles, compose files, dev containers, CircleCI, Kubernetes manifests (after file patterns are configured, kubernetes-manifests), and Ansible (docs.renovatebot.com, "Docker" and "Configuration options", accessed 2026-11-28)
Dependabot
package-ecosystem: "docker" "raises pull requests to update your base image tags and digests on a schedule" (docs.docker.com, "Building best practices"); docker-compose covers compose files (docs.github.com, "Supported ecosystems and repositories", accessed 2026-11-28)
Review the bot's pull request
Read the release notes for the new version, rebuild, rerun tests and the image scan; merge only on green
Local resource use
The docker CLI is a client; the long-running daemon dockerd creates and manages containers (docs.docker.com/engine, accessed 2026-11-28), so nice on the CLI does not lower the priority of the build or the container. Keep local builds and containers within the heavy-job cap in CLAUDE.md:
One build at a time unless the cap allows more. For a lasting limit, use a dedicated builder: docker buildx create --driver docker-container with the memory, cpu-quota, cpu-period, or cpuset-cpus driver options (docs.docker.com, "Docker container driver"), and --buildkitd-config pointing to a file with [worker.oci] max-parallelism = <N>, which limits parallel build steps (docs.docker.com, "Configure BuildKit"; both accessed 2026-11-28).
Containers run with --cpus=<n> and --memory=<size>; "by default, a container has no resource constraints" (docs.docker.com, "Resource constraints", accessed 2026-11-28).
Reproducibility
Pinned base digest, locked dependencies, and SOURCE_DATE_EPOCH set from the commit time (git log -1 --pretty=%ct) fix the timestamps in the image index, config, and file metadata (docs.docker.com, "Reproducible builds", accessed 2026-11-28).
Prove it: build twice from a clean cache and compare digests. Report differences; do not claim reproducibility untested.
Scan, SBOM, provenance
Triage scan findings with dependency-vulnerability-triage; scan images for secrets with secret-scanning.
Scan the built image with a pinned scanner (for example Trivy or Grype); report findings by severity and whether a fixed version exists. Fix by moving the base digest or package before proposing an exception.
BuildKit adds mode=min provenance by default; add an SBOM with --sbom=true (SPDX, in-toto) (docs.docker.com, "Build attestations", accessed 2026-11-28).
Compose files
Images pinned as image: <name>:<x.y.z>@sha256:<digest>, healthchecks with depends_on: condition: service_healthy, named volumes, and env_file pointing to an untracked file, with a committed .env.example that lists names only.
Validate with docker compose config --quiet; without --quiet it prints interpolated values, secrets included.
Stop with docker compose down, never -v; remove only volumes this task created, by name.
Procedure
Baseline. Read the Dockerfile, compose files, .dockerignore, build scripts, and the CI build job; record image size, build time, runtime user, and scan result.
Base. Choose the exact version tag, look up its digest, pin both, and confirm a renovation bot covers the file.
Write the build per the checks table.
Build and run locally within the heavy-job cap (docker buildx build --load); check user, entrypoint, and labels with docker image inspect --format on those fields only (the full output includes environment variables); confirm the container stops cleanly on SIGTERM.
Scan and SBOM; compare with the baseline.
Record results and hand over the push, tag, and sign steps to the pipeline or orchestrator.
Output
Image
Base (tag@digest)
Size before / after
Build time before / after
User
Findings C/H/M/L before / after
SBOM
Digest match on rebuild
Quality checklist
Every image reference (each FROM stage, COPY --from, the # syntax= frontend, compose image:) has an exact version and digest, and a renovation bot covers it; packages and tools are pinned exactly.
The final stage runs as a numeric non-root user and contains no build tools.
No secret in any layer, build argument, ENV, label, or build log; .dockerignore excludes .env*, keys, and .git.