[H1][DOCKERFILE-GENERATOR]
Dictum: Structured generation produces secure, minimal container images.
Docker Engine 27+ | BuildKit 0.27+ | Dockerfile syntax 1.14 | Node 24 LTS Krypton | Alpine 3.23
Tasks:
- Gather requirements -- language, version, framework, entry point, package manager
- Read dockerfile_knowledge.md -- Generation patterns and language substitution
- (framework research) Query context7 MCP or WebSearch for
"<framework> <version> dockerfile production 2026"
- Generate Dockerfile -- Apply universal template with language-specific substitution
- Generate .dockerignore -- See exemplar at
examples/example.dockerignore
- Validate -- Invoke dockerfile-validator (hadolint + Checkov + custom)
- Iterate -- Fix, re-validate, repeat (max 3 iterations)
Scope:
- Generation: Dockerfiles for Node.js (pnpm/npm), Python (uv), Go, Java, Rust
- Orchestration: docker-bake.hcl for monorepo multi-target builds
- Not: Validation (use dockerfile-validator), building/running containers, debugging
[1][REQUIREMENTS]
Dictum: Complete requirements prevent generation rework.
Guidance:
Language -- Language, version, framework, entry point, package manager (pnpm/npm/uv/go mod/maven/gradle)
Build -- Build commands, Nx target (monorepo), compilation flags, system deps.
Runtime -- Port(s), env vars, health endpoint, image size constraints, multi-arch (amd64/arm64).
Best-Practices:
- Base images (February 2026):
node:24-slim-trixie (pnpm), node:24-alpine3.23 (npm), python:3.14-slim-trixie, golang:1.24-alpine3.23, rust:1.84-slim-trixie, eclipse-temurin:21-jdk-alpine
- Chainguard:
cgr.dev/chainguard/node:latest-dev (build) / cgr.dev/chainguard/node:latest (runtime) -- daily CVE rebuilds, zero known vulnerabilities
[REFERENCE]: →dockerfile_knowledge.md -- Generation patterns, language substitution, cache mounts.
[2][MANDATORY_FEATURES]
Dictum: Every generated Dockerfile includes these features.
Guidance:
Syntax -- # syntax=docker/dockerfile:1 as first line (enables BuildKit frontend).
Multi-stage -- Named stages: deps, build, runtime (minimum).
Security -- Non-root USER 1001:1001, no secrets in ENV/ARG, exec-form ENTRYPOINT.
Best-Practices:
- BuildKit mounts:
--mount=type=cache for all pkg managers, --mount=type=secret,id=key,env=VAR for build secrets
- Layer optimization:
COPY --link on every COPY, COPY --chmod=555 (no extra RUN chmod layer), heredoc RUN <<EOF for multi-line scripts
- Metadata: OCI labels (
org.opencontainers.image.title/source/licenses/revision/created/version), Pulumi-injectable ARGs (GIT_SHA, BUILD_DATE, IMAGE_VERSION)
- Runtime:
HEALTHCHECK with --start-interval=2s (exec-form CMD), STOPSIGNAL SIGTERM, non-privileged ports (>1024)
[3][PNPM_MONOREPO]
Dictum: This project uses pnpm monorepo with Nx build orchestration.
Guidance:
Fetch-first -- pnpm fetch --frozen-lockfile downloads to store without installing (maximizes cache hits).
Deploy -- pnpm deploy --filter=@scope/app --prod /prod/app extracts standalone prod deployment.
Best-Practices:
- corepack:
RUN corepack enable (no global pnpm install)
- Offline install:
pnpm install --frozen-lockfile --offline --ignore-scripts
- Selective copy: Only needed
packages/*/package.json files (not entire workspace)
- Base image:
node:24-slim-trixie (glibc, Debian 13 -- not alpine for musl compat)
- Exemplar:
apps/api/Dockerfile is the production reference
[REFERENCE]: →dockerfile_knowledge.md -- pnpm monorepo pattern, cache mount targets.
[4][DELIVERABLES]
Dictum: Output quality measured by image size and security posture.
| [INDEX] |
[LANGUAGE] |
[ESTIMATED_SIZE] |
| [1] |
Node.js (slim-trixie) |
80-200 MB |
| [2] |
Python (slim-trixie) |
50-250 MB |
| [3] |
Go (distroless) |
5-20 MB |
| [4] |
Java (JRE) |
200-350 MB |
Deliverables: Validated Dockerfile + .dockerignore + validation summary.
Build command with attestations:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--sbom=true --provenance=mode=max \
--build-arg GIT_SHA="$(git rev-parse HEAD)" \
--build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-t myapp:latest --push .
[5][SCRIPTS]
Dictum: CLI generation enables standalone Dockerfile creation.
scripts/generate.sh -- Standalone CLI for Dockerfile generation.
./generate.sh nodejs -s @scope/app -p 4000 # pnpm monorepo
./generate.sh nodejs --standalone -p 3000 # standalone npm
./generate.sh python -p 8000 -e app.py # Python with uv
./generate.sh golang --distroless -p 8080 # Go distroless
./generate.sh golang --scratch -p 8080 # Go scratch
./generate.sh java -t maven -p 8080 # Java Maven
./generate.sh dockerignore -l nodejs # .dockerignore only
[6][VALIDATION]
Dictum: Gates prevent incomplete artifacts.
[VERIFY] Completion:
Integration:
- dockerfile-validator -- Validates generated Dockerfiles (REQUIRED)
- k8s-generator -- Kubernetes deployments for the container
- pulumi-k8s-generator -- Pulumi K8s resources with the container image
1---2name: dockerfile-generator-43description: Generates production-ready multi-stage Dockerfiles and .dockerignore files with BuildKit features, pnpm monorepo support, OCI labels, and security hardening. Use when creating or writing Dockerfiles for Node.js, Python, Go, Java, or Rust. Does not validate (use dockerfile-validator).4---5
6# [H1][DOCKERFILE-GENERATOR]
7>**Dictum:** *Structured generation produces secure, minimal container images.*
8
9<br>
10
11Docker Engine 27+ | BuildKit 0.27+ | Dockerfile syntax 1.14 | Node 24 LTS Krypton | Alpine 3.23
12
13**Tasks:**
141. Gather requirements -- language, version, framework, entry point, package manager
152. Read [dockerfile_knowledge.md](./references/dockerfile_knowledge.md) -- Generation patterns and language substitution
163. (framework research) Query context7 MCP or WebSearch for `"<framework> <version> dockerfile production 2026"`
174. Generate Dockerfile -- Apply universal template with language-specific substitution
185. Generate .dockerignore -- See exemplar at `examples/example.dockerignore`
196. Validate -- Invoke dockerfile-validator (hadolint + Checkov + custom)
207. Iterate -- Fix, re-validate, repeat (max 3 iterations)
21
22**Scope:**
23- *Generation:* Dockerfiles for Node.js (pnpm/npm), Python (uv), Go, Java, Rust
24- *Orchestration:* docker-bake.hcl for monorepo multi-target builds
25- *Not:* Validation (use dockerfile-validator), building/running containers, debugging
26
27---
28## [1][REQUIREMENTS]
29>**Dictum:** *Complete requirements prevent generation rework.*
30
31<br>
32
33**Guidance:**<br>
34- `Language` -- Language, version, framework, entry point, package manager (pnpm/npm/uv/go mod/maven/gradle)
35- `Build` -- Build commands, Nx target (monorepo), compilation flags, system deps.
36- `Runtime` -- Port(s), env vars, health endpoint, image size constraints, multi-arch (amd64/arm64).
37
38**Best-Practices:**<br>
39- **Base images (February 2026):** `node:24-slim-trixie` (pnpm), `node:24-alpine3.23` (npm), `python:3.14-slim-trixie`, `golang:1.24-alpine3.23`, `rust:1.84-slim-trixie`, `eclipse-temurin:21-jdk-alpine`
40- **Chainguard:** `cgr.dev/chainguard/node:latest-dev` (build) / `cgr.dev/chainguard/node:latest` (runtime) -- daily CVE rebuilds, zero known vulnerabilities
41
42[REFERENCE]: [→dockerfile_knowledge.md](./references/dockerfile_knowledge.md) -- Generation patterns, language substitution, cache mounts.
43
44---
45## [2][MANDATORY_FEATURES]
46>**Dictum:** *Every generated Dockerfile includes these features.*
47
48<br>
49
50**Guidance:**<br>
51- `Syntax` -- `# syntax=docker/dockerfile:1` as first line (enables BuildKit frontend).
52- `Multi-stage` -- Named stages: `deps`, `build`, `runtime` (minimum).
53- `Security` -- Non-root `USER 1001:1001`, no secrets in ENV/ARG, exec-form ENTRYPOINT.
54
55**Best-Practices:**<br>
56- **BuildKit mounts:** `--mount=type=cache` for all pkg managers, `--mount=type=secret,id=key,env=VAR` for build secrets
57- **Layer optimization:** `COPY --link` on every COPY, `COPY --chmod=555` (no extra RUN chmod layer), heredoc `RUN <<EOF` for multi-line scripts
58- **Metadata:** OCI labels (`org.opencontainers.image.title/source/licenses/revision/created/version`), Pulumi-injectable ARGs (`GIT_SHA`, `BUILD_DATE`, `IMAGE_VERSION`)
59- **Runtime:** `HEALTHCHECK` with `--start-interval=2s` (exec-form CMD), `STOPSIGNAL SIGTERM`, non-privileged ports (>1024)
60
61---
62## [3][PNPM_MONOREPO]
63>**Dictum:** *This project uses pnpm monorepo with Nx build orchestration.*
64
65<br>
66
67**Guidance:**<br>
68- `Fetch-first` -- `pnpm fetch --frozen-lockfile` downloads to store without installing (maximizes cache hits).
69- `Deploy` -- `pnpm deploy --filter=@scope/app --prod /prod/app` extracts standalone prod deployment.
70
71**Best-Practices:**<br>
72- **corepack:** `RUN corepack enable` (no global pnpm install)
73- **Offline install:** `pnpm install --frozen-lockfile --offline --ignore-scripts`
74- **Selective copy:** Only needed `packages/*/package.json` files (not entire workspace)
75- **Base image:** `node:24-slim-trixie` (glibc, Debian 13 -- not alpine for musl compat)
76- **Exemplar:** `apps/api/Dockerfile` is the production reference
77
78[REFERENCE]: [→dockerfile_knowledge.md](./references/dockerfile_knowledge.md) -- pnpm monorepo pattern, cache mount targets.
79
80---
81## [4][DELIVERABLES]
82>**Dictum:** *Output quality measured by image size and security posture.*
83
84<br>
85
86| [INDEX] | [LANGUAGE] | [ESTIMATED_SIZE] |
87| :-----: | ------------------------- | :--------------: |
88| [1] | **Node.js (slim-trixie)** | 80-200 MB |
89| [2] | **Python (slim-trixie)** | 50-250 MB |
90| [3] | **Go (distroless)** | 5-20 MB |
91| [4] | **Java (JRE)** | 200-350 MB |
92
93**Deliverables:** Validated Dockerfile + .dockerignore + validation summary.
94
95**Build command with attestations:**
96```bash
97docker buildx build \
98 --platform linux/amd64,linux/arm64 \
99 --sbom=true --provenance=mode=max \
100 --build-arg GIT_SHA="$(git rev-parse HEAD)" \
101 --build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
102 -t myapp:latest --push .
103```
104
105---
106## [5][SCRIPTS]
107>**Dictum:** *CLI generation enables standalone Dockerfile creation.*
108
109<br>
110
111`scripts/generate.sh` -- Standalone CLI for Dockerfile generation.
112
113```bash
114./generate.sh nodejs -s @scope/app -p 4000 # pnpm monorepo
115./generate.sh nodejs --standalone -p 3000 # standalone npm
116./generate.sh python -p 8000 -e app.py # Python with uv
117./generate.sh golang --distroless -p 8080 # Go distroless
118./generate.sh golang --scratch -p 8080 # Go scratch
119./generate.sh java -t maven -p 8080 # Java Maven
120./generate.sh dockerignore -l nodejs # .dockerignore only
121```
122
123---
124## [6][VALIDATION]
125>**Dictum:** *Gates prevent incomplete artifacts.*
126
127<br>
128
129[VERIFY] Completion:
130- [ ] Syntax directive: `# syntax=docker/dockerfile:1` as first line
131- [ ] Multi-stage: Named stages with minimal final base
132- [ ] Security: Non-root USER, no secrets in ENV/ARG, exec-form ENTRYPOINT
133- [ ] BuildKit: `COPY --link`, `--mount=type=cache`, heredoc RUN
134- [ ] Metadata: OCI labels, Pulumi ARGs, STOPSIGNAL, HEALTHCHECK with `--start-interval`
135- [ ] dockerfile-validator invoked and all issues resolved
136
137**Integration:**
138- **dockerfile-validator** -- Validates generated Dockerfiles (REQUIRED)
139- **k8s-generator** -- Kubernetes deployments for the container
140- **pulumi-k8s-generator** -- Pulumi K8s resources with the container image