Communityコーディング&開発github.com

ifundeasy/container-build

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.

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.

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ifundeasy/claude-crew/tree/HEAD/skills/container-build

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Container build

Rules

  • 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

AreaDoAvoid
BaseOfficial, verified, minimal, or distroless image; exact version plus digest; new bases evaluated with dependency-evaluationlatest, major or minor tags the publisher moves, unknown publishers
StagesBuild stage with the toolchain; final stage copies artifacts with COPY --fromShipping the toolchain
Context.dockerignore excluding .git, .env*, keys, local build output, and test dataSending secrets and history to the builder
Layer orderCopy lockfiles, install dependencies, then copy sources; apt-get update and install in one RUN; clean package caches in that layerapt-get update in its own layer; ADD of a remote URL without a checksum
PackagesExact versions where the ecosystem allows; no recommended extrasFloating versions
FilesystemApplication files owned by root and read-only to the app user; writable paths only where neededchmod 777; writable application code
ProcessExec-form ENTRYPOINT and CMD; the process handles SIGTERM; EXPOSE the ports usedShell form that swallows SIGTERM
HealthHEALTHCHECK 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 binaryA healthcheck that calls dependencies
LabelsOCI annotations org.opencontainers.image.source, .revision, .version, .created, .licenses, .base.name, .base.digest (github.com/opencontainers/image-spec, annotations.md, accessed 2026-11-28)Personal names or secrets in labels

Pinning and renovation

StepHow
Choose the tagThe most specific version tag the publisher offers (for example <x.y.z>-<variant><os-version>), not a major or latest alias
Find the digestdocker 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 pinFROM <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"
RenovatepinDigests 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)
Dependabotpackage-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 requestRead 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

  1. Baseline. Read the Dockerfile, compose files, .dockerignore, build scripts, and the CI build job; record image size, build time, runtime user, and scan result.
  2. Base. Choose the exact version tag, look up its digest, pin both, and confirm a renovation bot covers the file.
  3. Write the build per the checks table.
  4. 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.
  5. Scan and SBOM; compare with the baseline.
  6. Record results and hand over the push, tag, and sign steps to the pipeline or orchestrator.

Output

ImageBase (tag@digest)Size before / afterBuild time before / afterUserFindings C/H/M/L before / afterSBOMDigest 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.
  • Exec-form entrypoint; clean SIGTERM shutdown verified.
  • Image scanned and SBOM produced; findings at or above the threshold fixed or excepted with an expiry.
  • Built and run locally; size and build time recorded before and after.

Pitfalls

  • Deleting a secret file in a later RUN: it remains in the earlier layer.
  • A named non-root user without a numeric UID, so Kubernetes cannot verify runAsNonRoot and refuses the pod.
  • docker compose down -v in a script, wiping a developer's local database.
  • Pinning the base FROM but leaving COPY --from=<tool-image>:latest or # syntax=docker/dockerfile:1 floating: both are image pulls too.
  • Pinning digests by hand with no bot, so the image silently misses every security fix.

Individual skills in this repo

This repo contains 5 individual skills — each has its own dedicated page.

関連スキル