containers
Scope
Covers the container artefacts a repository owns and the runtime behaviour they
declare: Dockerfiles and the build that produces an image, image hardening and
supply-chain metadata, Compose files for local development, Kubernetes workload
manifests, Helm charts and Kustomize overlays, devcontainer.json, and the diagnosis
of a workload that will not start or will not drain.
Written against Docker Engine 29 with BuildKit, the Compose Specification as shipped in
Compose v5, Kubernetes 1.37 (current stable), Helm 4 and Kustomize 5. Rules needing
a server newer than 1.29 carry a gate such as (1.33+).
Not covered:
- Terraform, OpenTofu and HCL — module structure,
countversusfor_each, state moves, provider configuration. Use theterraformskill. - Build, scan and publish pipelines on GitHub Actions — workflow syntax,
permissions, OIDC to a registry, SHA pinning of actions. Use thegithubskill. This skill covers what the build does, not the workflow that runs it. - The application code inside the container. Use the
go,python,nodejs-backend,java-springorcsharp-dotnetskill; this skill only covers what the language runtime imposes on the image (entrypoint and signals, where dependencies live, what the runtime stage actually needs). - Managed cluster control planes — EKS, AKS and GKE node pools, cloud IAM and workload
identity, provider load balancers and CSI drivers, cluster upgrades through the
provider API. Use the
aws,azureorgcpskill for those. Everything here still holds for a workload running on a managed cluster. - Service meshes (Istio, Linkerd, Cilium Service Mesh) and their CRDs; GitOps controllers (Argo CD, Flux). Not covered by any skill in this library.
- Observability pipelines and dashboards — Prometheus Operator, OpenTelemetry
Collector, log shipping, alert rules. Use the
observabilityskill. This skill stops at what a manifest declares (probes,terminationGracePeriodSeconds, resource fields).
Paths below are relative to this skill's directory.
Read first
references/kubernetes-api-versions.md, before writing or reviewing any Kubernetes
manifest, chart template or overlay. It carries the removed-API table, the version gate
for every field this skill recommends, and the validation commands that work without a
cluster. Generated manifests reproduce API versions the server stopped serving years
ago, and a removed version is a hard rejection, not a warning.
Core rules
- Establish versions before applying a gated rule:
docker version,kubectl version,helm version, and the cluster's minor version. Half the container guidance in circulation predates BuildKit-by-default, Compose v2 and Kubernetes 1.25. - A credential passed as
ARG/--build-argis leaked, whether or not the stage that used it is shipped and whether or not the file it wrote was deleted. BuildKit keeps build-argument values in the build record of every build, and writes them into the provenance attestation whenever it is generated withmode=max(the defaultmode=minomits them). UseRUN --mount=type=secret,id=<name>and read/run/secrets/<name>; the mount exists only for that instruction and lands in no layer, record or attestation. [verified] docker historyis the wrong check for a leak. On an image built with a bareARG,docker historyanddocker inspect .Config.Envboth return nothing while the token sits in cleartext in the build record (docker buildx history inspect <build-ref>, refs fromdocker buildx history ls) and in anymode=maxattestation. For the attestation, build with--provenance=mode=maxand grepdocker buildx imagetools inspect <ref> --format '{{json .Provenance}}'for the credential pattern rather than the argument name; a defaultmode=minattestation reads clean either way. [verified]- Order a Dockerfile by rate of change: copy the dependency manifest, install, then copy
the source.
COPY . .before the install re-runs the install on every source edit, becauseCOPYinvalidates on the copied files' metadata. [verified] - Every image needs a
.dockerignore(or a<dockerfile>.dockerignore) that excludes at least.git, the host dependency directory and local env files. Without one the whole working tree is uploaded as build context andCOPY . .bakes it in — measured here as 73.5 MB of.gitand hostnode_modulesinside the image. [verified] - The runtime stage starts from a different, smaller image than the build stage.
Default to distroless,
scratchfor a statically linked binary, or the-slimvariant when a libc and a package manager are genuinely needed. Fall back to Alpine only when you mustexecinto the container to debug, and accept its cost: musl changes DNS resolution behaviour and breaks glibc-compiled wheels and native modules. COPY --from=build /app /appships the entire builder working tree — sources, dev dependencies, caches. Copy named artefacts, not directories you did not curate.- Reference base images and deployed images by digest, or at minimum a full patch
version. A tag is mutable:
node:20moves weekly, and withimagePullPolicy: IfNotPresenttwo nodes can run different code under one tag, which also makeskubectl rollout undomeaningless. - Use exec-form
CMD/ENTRYPOINT(CMD ["node", "dist/index.js"]). Shell form runs the process under/bin/sh -c, which does not forwardSIGTERM, so the container isSIGKILLed at the end of the grace period instead of shutting down. BuildKit warns about this asJSONArgsRecommended. [verified] - Set a non-root
USERin the runtime stage and make the Kubernetes side enforce it withrunAsNonRoot: true. AUSERline alone is advisory — a manifest can override it withrunAsUser: 0. - Compose files carry no top-level
version:. It is obsolete: Compose always validates against the current schema and warns when the key is present. [official] depends_on: [db]waits for the container to be created, not for the process to accept connections. Use the long form withcondition: service_healthyplus a realhealthcheckon the dependency, andcondition: service_completed_successfullyfor a migration or seed container that must finish first.- A one-shot service (migrate, seed, fixtures) belongs behind
profiles:so a plaindocker compose updoes not run it, and behind aservice_completed_successfullydependency so that when it does run, everything else waits for it. Profiles alone change "always runs" into "never runs". - Shadow a bind-mounted dependency directory with a container-owned volume
(
- /app/node_moduleson top of- .:/app), otherwise the host's platform-specific build replaces the image's. Better still, replace the whole-tree bind mount withdevelop.watch(action: syncfor sources,action: rebuildfor the dependency manifest) and rundocker compose watch; sync pushes changed files instead of paying bind-mount I/O on every read. - Liveness answers "is this process wedged?", readiness answers "can it serve right now?", startup answers "has it finished booting?". A liveness probe that touches a database or another service converts that dependency's outage into a simultaneous restart of every replica, and the restarts prevent recovery. Dependency checks go in readiness.
- While a startup probe is running, liveness and readiness are suspended. Any workload
with a slow boot needs one; size it as
failureThreshold × periodSeconds >worst observed startup. KeeptimeoutSeconds < periodSeconds, and never setfailureThreshold: 1on liveness — one slow response then kills the container. - Always set a memory limit; it is the only defence against one container taking the node down, and exceeding it is an OOMKill, not throttling. Prefer leaving CPU unlimited unless the workload is batch, multi-tenant or deliberately Guaranteed: a CPU limit is enforced by CFS quota, so the container is throttled at the ceiling inside every scheduling window even when the node is idle. Note the trade-off — without equal requests and limits the pod is Burstable and is evicted before Guaranteed pods under node pressure. [community]
- A PodDisruptionBudget whose budget is zero (
minAvailableequal toreplicas) makes the eviction API refuse forever, so a node drain hangs rather than fails. Express the budget asmaxUnavailable: 1so it tracks replica-count changes, and setunhealthyPodEvictionPolicy: AlwaysAllow(1.27+) so unready pods cannot wedge the drain either. - Default a web workload's rollout to
maxSurge: 1, maxUnavailable: 0— capacity is added before it is removed.maxUnavailable: 50%withmaxSurge: 0removes half the fleet for the entire rollout, which is exactly when load arrives at the rest. - The restricted Pod Security Standard needs all of
runAsNonRoot: true,allowPrivilegeEscalation: false,capabilities.drop: [ALL]andseccompProfile.type: RuntimeDefault; the first three alone are rejected by anenforce: restrictednamespace. AddreadOnlyRootFilesystem: trueandautomountServiceAccountToken: falseas well: neither is required by the standard, and both remove a real escalation path. - A literal secret in
env.valueis readable by anyone who canget deploymentorget podin the namespace, and it is in version control. UsevalueFrom.secretKeyRef, and treat a secret that reached a manifest as compromised — rotate it rather than only removing it. - Kubernetes pod-to-pod networking is flat by default: every pod can reach every other pod until a NetworkPolicy selects it. A namespace with no policy is not "using the default policy", it is unsegmented.
- Helm distributes configuration to other people — versioning, dependencies, a published chart. Kustomize expresses the differences between your own environments with no templating. Choose one per artefact; the only sane combination is Kustomize post-processing someone else's rendered chart.
kubectl apply --dry-run=clientis not offline validation: it fetches the OpenAPI schema and performs RESTMapper discovery, so it fails outright with no reachable cluster (even with--validate=false). The gates that work locally arekubeconform -kubernetes-version <x.y.z> -strict,kubectl kustomize,helm templateandhelm lint. [verified]- Diagnose from the object, not from the symptom name.
kubectl describe podpluskubectl get events --sort-by=.lastTimestampdistinguishes the four causes that all surface as "Pending" and the five that all surface as "CrashLoopBackOff". Quote the evidence before naming a root cause.
Workflows
write-or-slim-a-container-image
- Measure before changing:
docker image ls, thendocker history <ref>to see which instruction owns the bytes. Fix the largest layer first, not the tidiest one. - Split build from runtime and pick the runtime base by what the process actually
needs at run time (
references/dockerfile.md). - Reorder for cache: dependency manifest → install → source → build. Add
--mount=type=cachefor the package manager's own cache directory. - Write or fix
.dockerignore; prefer a deny-everything-then-allow form so a new secret file added later is excluded by default. - Move every build-time credential to
--mount=type=secret, and remove theARGand anyENVthat carried it (references/image-security.md). - Add
USER, exec-formCMD, and a digest or full-version base image pin. - Gate — the numbers and the leak checks: re-run the build, quote both sizes and
the cached-versus-rebuilt step list for a source-only change, and show the build
record (
docker buildx history inspect) plus a--provenance=mode=maxattestation grepped for the credential pattern, both returning zero.
review-a-kubernetes-manifest
- Check every
apiVersionagainst the target cluster's minor version first (references/kubernetes-api-versions.md). A removed version makes the rest of the review moot because the object cannot be created. - Read the probes as a set: which one checks dependencies, is there a startup budget,
does
timeoutSecondsfit insideperiodSeconds(references/kubernetes-workloads.md). - Check resources and the resulting QoS class, then the disruption story — PDB
budget, rollout parameters, spread across nodes and zones
(
references/kubernetes-resources.md). - Check the security posture against restricted PSS, plus service account,
RBAC and secret handling (
references/kubernetes-security.md). - Check the set is complete and internally consistent: a Service exists for every
Ingress backend, selectors match template labels, ports line up, and the
app.kubernetes.io/*labels are present. An Ingress for the retired community ingress-nginx controller is a migration finding, not a default (references/kubernetes-workloads.md). - Check image references are immutable and
imagePullPolicyagrees with them. - Gate — it validates offline:
kubeconform -kubernetes-version <cluster version> -strict -summaryover the rendered output returns zero invalid resources, and every finding names afile:line.
set-up-a-compose-development-environment
- Drop
version:, pin every image to a version tag, and name the project. - Give each dependency a real
healthcheck, then convertdepends_onto the long form withservice_healthy/service_completed_successfully(references/compose.md). - Put one-shot jobs behind
profiles:and wire the services that need them to wait for completion. - Replace the whole-tree bind mount with
develop.watch, or keep the bind mount and shadow the dependency directory with a volume. - Persist state in named volumes; publish a port to the host only when a host tool
needs it, bound to
127.0.0.1. - Gate — a cold start works:
docker compose config --quietis silent, thendocker compose down -v && docker compose up --waitreaches a healthy state with no manual step in between.
debug-a-pod-that-will-not-run
- Get the state before theorising:
kubectl get pod -o wide,kubectl describe pod,kubectl get events --sort-by=.lastTimestamp -n <ns>. - Read the previous container's logs, not the current one's, when it is restarting:
kubectl logs <pod> --previous(references/troubleshooting.md). - Map the phase to its real causes — Pending is scheduling (resources, taints, affinity, unbound PVC), CrashLoopBackOff is the process (exit code, OOMKill, config, failing liveness), ImagePullBackOff is the reference or the credentials.
- For an OOMKill read
kubectl get pod -o jsonpathforlastState.terminated.reasonandexitCode; exit 137 with reasonOOMKilledis the limit, exit 137 without it is aSIGKILLfrom elsewhere. - Reproduce the container's own view before changing the manifest:
kubectl debugwith an ephemeral container, or run the image locally with the same command. - Gate — the fix is tied to evidence: quote the event, the exit code or the log line that names the cause, then show the same command clean after the change.
choose-and-structure-helm-or-kustomize
- Decide by consumer, not by taste (Core rule 23), and record the decision in the repository so the next change does not re-open it.
- For Helm: keep templates free of logic that belongs in
values.yaml, give every value a default and avalues.schema.json, and never template anapiVersionwithout a.Capabilitiesguard (references/helm-and-kustomize.md). - For Kustomize: a base that is deployable on its own, overlays that only express differences, strategic-merge patches for structure and JSON-6902 patches for list surgery.
- Keep generated ConfigMaps and Secrets hash-suffixed so a config change actually rolls the pods.
- Gate — render then validate:
helm templateorkubectl kustomizepiped intokubeconform -strict, plushelm lintfor a chart. Compare the rendered diff, not the template diff, when reviewing a change.
deploy-a-gpu-workload
Read references/kubernetes-gpu.md. Everything the serving process does with the
card once it has one - KV cache sizing, batching, parallelism, benchmarking,
scaling signals - is the model-serving skill.
- Prove the device is offered before reading anything else: the discriminator is
whether the resource key exists in
allocatableat all, not whether its value is low.CapacityaboveAllocatablemeans unhealthy devices, not quota. - Establish whether the pool is shared, and how. A count that is a multiple of the
physical card count is the time-slicing replica multiplier; check whether
renameByDefaultmoved the resource tonvidia.com/gpu.shared, or a MIG strategy tonvidia.com/mig-<n>g.<m>gb. A wrong resource name is a permanently Pending pod with no error. - State the isolation the sharing method actually provides. Time-slicing gives neither memory nor fault isolation, so a memory floor per replica cannot be met that way - that needs MIG or an exclusive card.
- Declare the GPU in
limits(integer, no overcommit), then select the right card: the extended resource keeps the pod off CPU nodes but nothing keeps it off the smaller GPU without anodeSelector/nodeAffinityon a GPU label. - Check the driver against the image's CUDA family, and keep driver packages out of the image - driver user-space is injected from the host at container creation.
- Confirm the runtime path:
runtimeClassNamewhen the nvidia runtime is not the cluster default, and the NVIDIA environment variables that a non-CUDA runtime base image drops. - Size the startup probe from a measured GPU cold start, not from the CPU service's budget; driver init, device memory allocation and PTX JIT all land before the first successful probe.
- Gate:
kubectl apply --dry-run=serverorkubeconform -strict, and name which claims are unverifiable without the cluster (device plugin state, labels, driver version) rather than asserting them.
Topic router
| Topic | Read when | File |
|---|---|---|
| Removed and deprecated API versions by release, the version gate for every field this skill recommends, and the validation commands that work without a cluster | Before writing or reviewing any manifest, chart template or overlay | references/kubernetes-api-versions.md |
Stage structure, base-image selection, cache ordering and cache mounts, .dockerignore semantics, entrypoints and signals, multi-architecture builds, build lint | Writing or slimming a Dockerfile, or a build is slow | references/dockerfile.md |
| Build secrets and the provenance leak, non-root and read-only runtime, registry references and digests, scanning, SBOM and signing, what a container runtime does and does not isolate | Hardening an image or auditing how one was built | references/image-security.md |
Compose file shape without version:, healthchecks and dependency conditions, profiles, develop.watch, volumes and bind-mount shadowing, networks and ports, include/extends | Building or fixing a local development environment | references/compose.md |
| Deployment, StatefulSet, Job and CronJob shape, Service types and Ingress, ConfigMap and Secret wiring, probes, lifecycle and graceful shutdown, rollout strategy and rollback, sidecars | Writing or reviewing a workload manifest | references/kubernetes-workloads.md |
| Requests, limits and QoS, OOMKill and CFS throttling, LimitRange and ResourceQuota, HPA, PodDisruptionBudget, node affinity, taints and topology spread, in-place resize | Sizing a workload, or scheduling and disruption behave oddly | references/kubernetes-resources.md |
| Extended-resource contract for GPUs, device plugin state, time-slicing/MPS/MIG and their isolation, RuntimeClass and the NVIDIA environment variables, driver/CUDA compatibility, GPU node selection, DRA, driver-upgrade drains | A workload needs a GPU, or has one and cannot see it | references/kubernetes-gpu.md |
| securityContext field by field, Pod Security Standards and Pod Security Admission labels, ServiceAccount and RBAC, secret handling, NetworkPolicy, user namespaces | Hardening a workload or reviewing its blast radius | references/kubernetes-security.md |
| When each tool fits, chart layout and values design, capability guards and hooks, overlay and patch strategy, generators and hash suffixes, the combinations that go wrong | Packaging manifests for more than one environment | references/helm-and-kustomize.md |
| Pending, CrashLoopBackOff, ImagePullBackOff, OOMKilled, Terminating, 502 from an Ingress, DNS failures — the evidence that separates their causes | A workload is broken and you need the cause, not a guess | references/troubleshooting.md |
devcontainer.json review rules, the image-metadata merge that makes absence unprovable, lifecycle command ordering and prebuilds, Features, remoteUser and UID handling | Writing or reviewing a dev container or Codespaces configuration | references/devcontainers.md |
Output format
When reviewing a Dockerfile, compose file or manifest set, group findings by file and lead each with the location and the consequence:
k8s/checkout/deployment.yaml:34 - blocking - livenessProbe hits /health, which queries Postgres. A database blip fails the probe on all 3 replicas at once and the kubelet restarts them together. Move the dependency check to readinessProbe; point liveness at a handler that only reports process health.
Order findings by blast radius: first anything that makes the object impossible to
create (a removed apiVersion, a schema error), then anything that causes an outage
(probe semantics, a zero-budget PDB, a leaked credential), then correctness, then size
and style. For a size or build-time finding quote the measurement (docker history
line, image size, which steps were CACHED) rather than asserting an improvement, and
give the before/after snippet.
Environment
- Docker Engine 24+ with BuildKit for
--mount=type=secretand--mount=type=cache;docker buildx imagetools inspectneeds an image in a registry or an OCI export, and provenance attestations and multi-platform images need the containerd image store (the default on Docker Engine 29+ and Docker Desktop; an engine upgraded from an older version may still use classic storage) or adocker-containerbuilder. Without either the build fails with "Attestation is not supported for the docker driver". kubeconformis the offline schema validator used by the gates above; it is a single binary orghcr.io/yannh/kubeconform. It needs network access the first time to fetch the schema set for the requested Kubernetes version.kubectlneeds a reachable cluster for anything that touches discovery, includingapply --dry-run=client.kubectl create --dry-run=client -o yamlandkubectl kustomizeare the two subcommands that work with no cluster at all.- Helm 4 is current; Helm 3 left bug-fix support in 2026 and receives security fixes
only.
helm templateandhelm lintare offline;--dry-run=serveris not. - Say which tools are actually present rather than assuming. A review performed by reading files is still a review — state that nothing was executed.


