Docker Architect
Overview
Produce production-grade, secure, right-sized Docker images and Compose environments end-to-end: inventory → design → implement → test → CI. Prefer minimal, reproducible builds (multi-stage + BuildKit) and least-privilege runtime defaults.
Quick Start (always do this first)
Resolve skill_dir as the directory containing this skill before running
bundled scripts.
- Inventory the repo and existing container config:
- Run
python3 "$skill_dir/scripts/docker_inventory.py" --root .
- Choose the target:
- New containerization → follow “New build workflow”
- Existing Dockerfiles/Compose → follow “Audit + refactor workflow”
- Validate locally:
docker buildx version
docker buildx build ... (or docker build ...)
docker compose config and docker compose up --build
Template rendering example (edit variables per repo):
python3 "$skill_dir/scripts/render_template.py" --template .dockerignore --out .dockerignore
python3 "$skill_dir/scripts/render_template.py" --template compose/docker-compose.yml --out docker-compose.yml --var IMAGE_NAME=myapp:dev --var HOST_PORT=8000 --var CONTAINER_PORT=8000
python3 "$skill_dir/scripts/render_template.py" --template compose/docker-compose.dev.yml --out docker-compose.dev.yml --var CONTAINER_PORT=8000 --var DEV_COMMAND='[\"python\",\"-m\",\"uvicorn\",\"myapp.api:app\",\"--host\",\"0.0.0.0\",\"--port\",\"8000\",\"--reload\"]'
Workflow Decision Tree
- Scope:
- Dev-only (fast iteration, source mounts, hot reload) → prefer
docker-compose.dev.yml
- Prod-like (immutable images, healthchecks, least privilege) → prefer
docker-compose.yml + docker-compose.prod.yml
- Artifact type:
- Single service → one Dockerfile + optional compose for deps
- Multi-service → compose with explicit networks/volumes and healthchecks
- Publish target:
- Local only → keep simple; optional CI smoke checks
- Registry publish → add CI build/test/scan/push + provenance/SBOM (if available)
New build workflow (Dockerfile + .dockerignore + compose)
- Pick a base strategy (see
references/dockerfile_patterns.md):
- Multi-stage build; runtime image is minimal; build tools stay in builder stage.
- Prefer slim/distroless where feasible; default to non-root user.
- Add
.dockerignore early (template in assets/templates/.dockerignore).
- Create a Dockerfile from templates:
- Prefer
assets/templates/python/Dockerfile.uv for modern Python/uv
- Prefer
assets/templates/node/Dockerfile.pnpm for Node + pnpm
- Use
python3 "$skill_dir/scripts/render_template.py" ... to render with variables.
- Add a compose file for dependencies (DB/cache) and dev/prod profiles:
- Start from
assets/templates/compose/docker-compose.yml + an override (assets/templates/compose/docker-compose.dev.yml or assets/templates/compose/docker-compose.prod.yml)
- Optional deps file:
assets/templates/compose/docker-compose.deps.yml
- Local validation:
bash "$skill_dir/scripts/smoke_test_container.sh" --help
- Optional:
--build-check (Docker build checks) and --pull (fresh base images)
- For compose:
bash "$skill_dir/scripts/smoke_test_compose.sh" --help
Audit + refactor workflow (existing Dockerfiles/Compose)
- Inventory + static audit:
python3 "$skill_dir/scripts/docker_audit.py" --root .
- Identify high-risk issues (see
references/security_hardening.md):
- Secrets in image/build args, root/privileged runtime, overly broad mounts, host networking, “latest” tags, missing healthchecks.
- Refactor incrementally:
- Keep behavior stable, then tighten (non-root, read-only fs, drop caps, pin images, shrink layers).
- Validate end-to-end:
docker buildx build ...
docker compose up --build and run the app’s normal test/health commands.
- Produce a concise report (template in
references/review_template.md).
CI integration workflow (GitHub Actions default)
- Start from
assets/templates/ci/github-actions-docker-ci.yml.
- For publish + SBOM/provenance to GHCR:
assets/templates/ci/github-actions-docker-publish.yml
- Ensure CI runs:
docker buildx build (cache enabled)
docker compose config (compose validation)
- optional: build checks (
docker build --check) and scan/SBOM/provenance steps
- Prefer pinned action versions and least-privilege permissions (see
references/ci_github_actions.md).
“Latest/correct” research rule (do not guess)
When “latest” matters (base images, distro versions, language runtimes, CVEs):
- Use Exa to confirm current official guidance and tags (official sources preferred).
- Use
docker buildx imagetools inspect <image:tag> to confirm manifests/platforms.
- If unsure, mark as
UNVERIFIED and propose a safe default with a verification step.
Tooling leverage (when it helps)
- Exa: find current best practices, base image changes, CVE guidance, GitHub Actions deprecations.
- Context7: confirm framework-specific build outputs (e.g., Next.js, FastAPI, uvicorn/gunicorn, etc.).
- Zen: use
zen.secaudit for a structured container/security audit and zen.analyze for architecture-sensitive compose design.
- gh_grep: search public repos for battle-tested patterns (entrypoints, healthchecks, buildx/bake, compose profiles).
- opensrc: inspect dependency internals when container behavior depends on packaging details.
Bundled resources
Scripts
scripts/docker_inventory.py: detect stack + existing Docker/Compose files.
scripts/docker_audit.py: heuristic linting of Dockerfiles/Compose for security/correctness.
scripts/render_template.py: render templates with {{VARS}} into repo files.
scripts/smoke_test_container.sh: build/run basic health check locally.
scripts/smoke_test_compose.sh: validate + bring up compose and check health.
References (load as needed)
references/dockerfile_patterns.md: BuildKit, caching, multi-stage, runtime hardening.
references/compose_patterns.md: compose patterns, profiles, healthchecks, secrets/configs.
references/security_hardening.md: least privilege, capabilities, read-only fs, supply chain.
references/ci_github_actions.md: CI build/test/scan/publish patterns.
references/review_template.md: audit report format and deliverables checklist.
Assets (templates)
Templates live under assets/templates/ (Dockerfile variants, compose variants, CI workflow, .dockerignore, docker-bake.hcl).
1---2name: docker-architect3description: Docker + Compose—arch, implement, harden, CI. Triggers—Dockerfile, compose, bake, dockerignore, audit, build/run debug, multi-svc dev/prod.4---56# Docker Architect78## Overview910Produce production-grade, secure, right-sized Docker images and Compose environments end-to-end: inventory → design → implement → test → CI. Prefer minimal, reproducible builds (multi-stage + BuildKit) and least-privilege runtime defaults.1112## Quick Start (always do this first)1314Resolve `skill_dir` as the directory containing this skill before running15bundled scripts.16171. Inventory the repo and existing container config:18 - Run `python3 "$skill_dir/scripts/docker_inventory.py" --root .`192. Choose the target:20 - **New containerization** → follow “New build workflow”21 - **Existing Dockerfiles/Compose** → follow “Audit + refactor workflow”223. Validate locally:23 - `docker buildx version`24 - `docker buildx build ...` (or `docker build ...`)25 - `docker compose config` and `docker compose up --build`2627Template rendering example (edit variables per repo):2829- `python3 "$skill_dir/scripts/render_template.py" --template .dockerignore --out .dockerignore`30- `python3 "$skill_dir/scripts/render_template.py" --template compose/docker-compose.yml --out docker-compose.yml --var IMAGE_NAME=myapp:dev --var HOST_PORT=8000 --var CONTAINER_PORT=8000`31- `python3 "$skill_dir/scripts/render_template.py" --template compose/docker-compose.dev.yml --out docker-compose.dev.yml --var CONTAINER_PORT=8000 --var DEV_COMMAND='[\"python\",\"-m\",\"uvicorn\",\"myapp.api:app\",\"--host\",\"0.0.0.0\",\"--port\",\"8000\",\"--reload\"]'`3233## Workflow Decision Tree34351. Scope:36 - **Dev-only** (fast iteration, source mounts, hot reload) → prefer `docker-compose.dev.yml`37 - **Prod-like** (immutable images, healthchecks, least privilege) → prefer `docker-compose.yml` + `docker-compose.prod.yml`382. Artifact type:39 - **Single service** → one Dockerfile + optional compose for deps40 - **Multi-service** → compose with explicit networks/volumes and healthchecks413. Publish target:42 - **Local only** → keep simple; optional CI smoke checks43 - **Registry publish** → add CI build/test/scan/push + provenance/SBOM (if available)4445## New build workflow (Dockerfile + .dockerignore + compose)46471. Pick a base strategy (see `references/dockerfile_patterns.md`):48 - Multi-stage build; runtime image is minimal; build tools stay in builder stage.49 - Prefer slim/distroless where feasible; default to non-root user.502. Add `.dockerignore` early (template in `assets/templates/.dockerignore`).513. Create a Dockerfile from templates:52 - Prefer `assets/templates/python/Dockerfile.uv` for modern Python/`uv`53 - Prefer `assets/templates/node/Dockerfile.pnpm` for Node + pnpm54 - Use `python3 "$skill_dir/scripts/render_template.py" ...` to render with variables.554. Add a compose file for dependencies (DB/cache) and dev/prod profiles:56 - Start from `assets/templates/compose/docker-compose.yml` + an override (`assets/templates/compose/docker-compose.dev.yml` or `assets/templates/compose/docker-compose.prod.yml`)57 - Optional deps file: `assets/templates/compose/docker-compose.deps.yml`585. Local validation:59 - `bash "$skill_dir/scripts/smoke_test_container.sh" --help`60 - Optional: `--build-check` (Docker build checks) and `--pull` (fresh base images)61 - For compose: `bash "$skill_dir/scripts/smoke_test_compose.sh" --help`6263## Audit + refactor workflow (existing Dockerfiles/Compose)64651. Inventory + static audit:66 - `python3 "$skill_dir/scripts/docker_audit.py" --root .`672. Identify high-risk issues (see `references/security_hardening.md`):68 - Secrets in image/build args, root/privileged runtime, overly broad mounts, host networking, “latest” tags, missing healthchecks.693. Refactor incrementally:70 - Keep behavior stable, then tighten (non-root, read-only fs, drop caps, pin images, shrink layers).714. Validate end-to-end:72 - `docker buildx build ...`73 - `docker compose up --build` and run the app’s normal test/health commands.745. Produce a concise report (template in `references/review_template.md`).7576## CI integration workflow (GitHub Actions default)77781. Start from `assets/templates/ci/github-actions-docker-ci.yml`.79 - For publish + SBOM/provenance to GHCR: `assets/templates/ci/github-actions-docker-publish.yml`802. Ensure CI runs:81 - `docker buildx build` (cache enabled)82 - `docker compose config` (compose validation)83 - optional: build checks (`docker build --check`) and scan/SBOM/provenance steps843. Prefer pinned action versions and least-privilege permissions (see `references/ci_github_actions.md`).8586## “Latest/correct” research rule (do not guess)8788When “latest” matters (base images, distro versions, language runtimes, CVEs):89901. Use Exa to confirm current official guidance and tags (official sources preferred).912. Use `docker buildx imagetools inspect <image:tag>` to confirm manifests/platforms.923. If unsure, mark as `UNVERIFIED` and propose a safe default with a verification step.9394## Tooling leverage (when it helps)9596- **Exa**: find current best practices, base image changes, CVE guidance, GitHub Actions deprecations.97- **Context7**: confirm framework-specific build outputs (e.g., Next.js, FastAPI, uvicorn/gunicorn, etc.).98- **Zen**: use `zen.secaudit` for a structured container/security audit and `zen.analyze` for architecture-sensitive compose design.99- **gh_grep**: search public repos for battle-tested patterns (entrypoints, healthchecks, buildx/bake, compose profiles).100- **opensrc**: inspect dependency internals when container behavior depends on packaging details.101102## Bundled resources103104### Scripts105106- `scripts/docker_inventory.py`: detect stack + existing Docker/Compose files.107- `scripts/docker_audit.py`: heuristic linting of Dockerfiles/Compose for security/correctness.108- `scripts/render_template.py`: render templates with `{{VARS}}` into repo files.109- `scripts/smoke_test_container.sh`: build/run basic health check locally.110- `scripts/smoke_test_compose.sh`: validate + bring up compose and check health.111112### References (load as needed)113114- `references/dockerfile_patterns.md`: BuildKit, caching, multi-stage, runtime hardening.115- `references/compose_patterns.md`: compose patterns, profiles, healthchecks, secrets/configs.116- `references/security_hardening.md`: least privilege, capabilities, read-only fs, supply chain.117- `references/ci_github_actions.md`: CI build/test/scan/publish patterns.118- `references/review_template.md`: audit report format and deliverables checklist.119120### Assets (templates)121122Templates live under `assets/templates/` (Dockerfile variants, compose variants, CI workflow, `.dockerignore`, `docker-bake.hcl`).