kadet-hub logokadet-hub

Generators / docker

docker

1.1.0

Renders Dockerfiles, single- or multi-stage, from short image descriptions in the inventory, with package installation for the base image's distribution and non-root user setup, and a Docker Compose file from the kubernetes generator's components.

Request a feature Report a problem

Badge

Show the latest listed version in your README. shields.io draws the badge from this page's badge.json, which every catalog build updates; once no version is listed, it reads "not listed".

[![kadet-hub](https://img.shields.io/endpoint?url=https://kadet-hub.org/generators/docker/badge.json)](https://kadet-hub.org/generators/docker/)
Latest
1.1.0 ·
License
Apache-2.0
Owners
Moep90
Source
github.com/kadet-hub/generators · 0 repo stars, shared by 38 generators
Thumbs up
👍 0 on GitHub Discussions
Popularity
21 · 1710 pulls
Image security
Version 1.1.0 names no image.

Docker Generator

Published on kadet-hub: pin a released version by digest from its catalog page.

Kapitan kadet generator for Dockerfiles and, from the components of the kubernetes generator, a Docker Compose file (Docker Compose). Each entry under dockerfiles renders one Dockerfile, single-stage or multi-stage. From a short image description it derives the package install command for the base image’s distribution (apk add --no-cache, apt-get with cache mounts for /var/cache/apt and /var/lib/apt/lists, so neither ends up in the image, dnf with dnf clean all, or pip --no-cache-dir), creates a non-root user with the matching userland (busybox adduser on Alpine, shadow useradd elsewhere) and writes the instructions in a fixed order that builds.

Built for BuildKit’s Dockerfile frontend 1.20 or later, per the Dockerfile reference at BuildKit v0.34.0: RUN --mount (also used for apt installs) and COPY --chmod need Dockerfile 1.2, RUN --network 1.3, RUN --security 1.20, and RUN --security=insecure also needs the security.insecure entitlement on the builder and the build. BuildKit is the default builder on Linux since Docker Engine 23.0.0.

Usage

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/docker@sha256:<digest>
        output_path: lib/docker
    compile:
      - output_path: docker/
        input_type: kadet
        output_type: plain
        input_paths:
          - lib/docker
  generators:
    docker:
      dockerfiles:
        orders-api:
          stages:
            - stage_name: builder
              base_image: python:3.14.8-slim-trixie
              workdir: /build
              packages: [build-essential]
              copy:
                - src: requirements.txt
                  dst: .
              run:
                - python -m venv /opt/venv
                - command: /opt/venv/bin/pip install -r requirements.txt
                  mount: type=cache,target=/root/.cache/pip
            - stage_name: runtime
              base_image: python:3.14.8-slim-trixie
              labels:
                org.opencontainers.image.source: https://git.example.com/shop/orders-api
              env:
                PATH: /opt/venv/bin:$PATH
              workdir: /app
              create_user: true
              user: app
              uid: 10001
              gid: 10001
              copy:
                - src: /opt/venv
                  dst: /opt/venv
                  from: builder
                - src: src/
                  dst: /app/
                  chown: "10001:10001"
              expose: [8000]
              cmd: ["python", "-m", "orders_api", "--port", "8000"]

output_type: plain is required: the generator returns the Dockerfile text.

Inputs

All keys live under parameters.generators.docker.dockerfiles.<name>. A Dockerfile has either the stage keys below or stages, a list of stages with the same keys. Every stage needs base_image.

Key Instruction
component Output directory instead of <name>; may contain /. Top level only.
base_image, platform, stage_name FROM [--platform=…] <image> [AS <stage>]
labels one LABEL k="v" per entry
args one ARG k[=v] per entry; null declares without default
env one ENV k="v" per entry
workdir WORKDIR
packages, package_manager one install RUN; package_manager is auto (default, from the image name: alpine is apk, fedora/centos/rhel/rocky/alma is dnf, everything else apt), apk, apt, dnf or pip
create_user, user, uid, gid with create_user: true, a RUN that creates group and user (uid/gid default 1000); user alone only emits USER
copy COPY; an item is a string ("src dst") or a dict with src, dst, from, chown, chmod
run RUN; an item is a string, a list (joined with &&) or a dict with command, mount, network (default, none, host), security (sandbox, insecure)
volumes, expose one VOLUME / EXPOSE per item
healthcheck NONE, or a dict with cmd (string or list), interval, timeout, start_period, retries
entrypoint, cmd list for exec form, string for shell form

Instructions are written in the order of the table, with packages before user creation and USER, so packages always install as root; the RUN steps after it run as user, and copied files stay owned by root unless chown is set. Without user the image’s default user applies, which is root for most official images; set user for anything that does not need root at runtime. Values that would break a single-line instruction (newlines) are rejected, as are unknown package_manager, network and security values and out-of-range uid, gid and ports.

Build secrets do not belong in args or env, where they end up in the image history; use run with mount: type=secret,id=<id>.

Docker Compose

generators.docker.compose turns on compose.yml, written next to the Dockerfiles by the same compile entry. It renders parameters.components, the block the kubernetes generator reads, so one class feeds a cluster target and a Docker host target. Each component becomes the service of the same name, after the kubernetes generator’s defaults (applications.<app>.component_defaults, generators.manifest.default_config, generators.manifest.resource_defaults.<type>). A component with enabled: false renders no service.

parameters:
  components:                 # usually in a class the cluster target shares
    miniflux:
      image: miniflux/miniflux:2.3.4@sha256:<digest>
      ports:
        http:
          container_port: 8080
      env:
        ADMIN_PASSWORD:
          secretKeyRef:
            key: ADMIN_PASSWORD
      secrets:
        credentials:
          string_data:
            ADMIN_PASSWORD:
              value: ?{base64:miniflux/admin-password||random:str:24}
      healthcheck:
        readiness:
          type: command
          command: [/usr/bin/miniflux, -healthcheck, auto]
  generators:
    docker:
      compose:                # merged over what the components render
        services:
          miniflux:
            ports: [127.0.0.1:8080:8080]
Component key Compose
image image
command; args as list or mapping entrypoint; command
env: scalars, and secretKeyRef or configMapKeyRef with only key environment, the value taken from the component’s secrets.<s>.string_data or config_maps.<c>.data entry with value
ports expose: the container port, with /udp or /sctp for those protocols
volume_claims; volume_mounts of a claim (mount_path, volume, read_only) a named volume per claim; <claim>:<mount_path>[:ro]
healthcheck.readiness with type: command healthcheck: period_seconds, timeout_seconds, failure_threshold and initial_delay_seconds as interval, timeout, retries and start_period, defaults 10, 5, 3 and 0 as the kubernetes generator renders them
resources: cpu, and memory in Ki, Mi or Gi deploy.resources, requests as reservations; on one Docker host Compose applies no CPU reservation
security_context: runAsUser, runAsGroup, readOnlyRootFilesystem; read_only_root_filesystem user; read_only
type: deployment, statefulset restart: always
application, enabled, service, enable_service_links: false nothing; services reach each other by service name on the container port

Any other component key, and a value the table does not cover, fails the compile with components.<name>: no Compose mapping for <key>. That includes security_profile, workload_security_context, replicas, init_containers, volumes, labels and annotations, liveness and startup probes and readiness probes of type http, tcp or grpc: a Compose health check runs inside the container and needs a client the image has. Keep such keys in the cluster target, and put a Compose healthcheck under generators.docker.compose.services.<name>.

generators.docker.compose is merged over the rendered document: mappings key by key, other values replace, null removes. It holds what only a Docker host needs, such as published ports, depends_on, another restart or services that are no component, and is written as given, with Compose interpolation. Values taken from components have $ written as $$, so the container gets them as Kubernetes passes them. env, command and args with $( or $$ fail the compile, because Kubernetes expands those and Compose does not.

Compile without --reveal and reveal on the host, so no file holds the secrets:

kapitan compile -t <target>
kapitan refs --reveal -f compiled/<target>/docker/compose.yml | docker compose -p <project> -f - up -d

Kapitan writes revealed values into the text unescaped and unquoted, so a $ in one is interpolated by Compose and a value starting with a YAML indicator such as * breaks the file. random:str refs contain letters and digits only.

Output

File Content
<output_path>/<name>/Dockerfile one Dockerfile per entry, or <output_path>/<component>/Dockerfile
<output_path>/compose.yml the Compose file, with generators.docker.compose set

Versions

Add a version's inventory entry, then compile with the consumer workflow, which verifies the artifact and runs Kapitan in the sandbox.

Free of charge, as is and on a best-effort basis: use at your own risk, and review the compiled output before you apply it. Terms

This catalog was built from index serial 148. Set index_serial: 148 in .kapitan-sandbox.yaml and the consumer workflow refuses any older index, so a rolled-back index cannot bring back a yanked version.

Checks find known patterns; they do not prove a generator safe. What a listing covers

VersionBuilt for (schema-checked)
1.1.0not recorded
1.0.2not recorded
1.0.1not recorded
1.1.0

1Inventory Your project

Inventory entry

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/docker:1.1.0@sha256:7d3cee390791fefab8f563d5a9ece6c070b873444e05a46e9f6ac7268b3f8121
        output_path: lib/docker

2Verify kadet-hub

Terminal

gh attestation verify \
  oci://ghcr.io/kadet-hub/docker@sha256:7d3cee390791fefab8f563d5a9ece6c070b873444e05a46e9f6ac7268b3f8121 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3744006148, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

3Checks kadet-hub

Checked by the release run on , gate at 9a6bbc02afd7.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.183.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.3
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest v0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Record

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
reclass-rs, omegaconf
With --cache
passed
krab
compatible
Built for (schema-checked)
not recorded
Source
docker-v1.1.0 · docker
Source commit
6b11c3f03aa56a479ffe159683ccd99420311dce
Binaries
none
Output capabilities
none
Digest
sha256:7d3cee390791fefab8f563d5a9ece6c070b873444e05a46e9f6ac7268b3f8121

Output diff

Fixture output against 1.0.2: 1 file, 1 hunk.

--- a/compiled/compose/docker/compose.yml
+++ b/compiled/compose/docker/compose.yml
@@ -0,0 +1,67 @@
+services:
+  miniflux:
+    image: miniflux/miniflux:2.3.4@sha256:72e49f513a63104506aab98ba8cfc3a409d4fde23550a583dec07ec941f1e94e
+    user: 65534:65534
+    read_only: true
+    environment:
+      DATABASE_URL: postgres://miniflux:?{base64:fixture/db-password:7fc15e8c}@miniflux-db/miniflux?sslmode=disable
+      RUN_MIGRATIONS: '1'
+      CREATE_ADMIN: '1'
+      ADMIN_USERNAME: admin
+      ADMIN_PASSWORD: ?{base64:fixture/admin-password:47397b23}
+      POLLING_FREQUENCY: '60'
+    expose:
+    - '8080'
+    healthcheck:
+      test:
+      - CMD
+      - /usr/bin/miniflux
+      - -healthcheck
+      - auto
+      interval: 5s
+      timeout: 5s
+      retries: 3
+    deploy:
+      resources:
+        limits:
+          cpus: '0.5'
+          memory: 256m
+        reservations:
+          cpus: '0.05'
+          memory: 64m
+    restart: always
+    ports:
+    - 127.0.0.1:8080:8080
+    depends_on:
+      miniflux-db:
+        condition: service_healthy
+  miniflux-db:
+    image: postgres:18.6@sha256:edb0c08dc33befd0262ab3b5cf1c4f3f8cfd8b09e88c05b45adee29d6761ddb6
+    command:
+    - -c
+    - max_connections=50
+    environment:
+      POSTGRES_USER: miniflux
+      POSTGRES_PASSWORD: ?{base64:fixture/db-password:7fc15e8c}
+      POSTGRES_DB: miniflux
+    expose:
+    - '5432'
+    volumes:
+    - miniflux-db:/var/lib/postgresql
+    healthcheck:
+      test:
+      - CMD
+      - pg_isready
+      - -U
+      - miniflux
+      interval: 10s
+      timeout: 30s
+      retries: 3
+      start_period: 5s
+    deploy:
+      resources:
+        limits:
+          memory: 512m
+    restart: always
+volumes:
+  miniflux-db: {}

Output diff

1.0.2

1Inventory Your project

Inventory entry

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/docker:1.0.2@sha256:ef5bfec5d416778a1d9067b0a1666a77c53aa1d1bc76cfbb5f9f7b034a7cd422
        output_path: lib/docker

2Verify kadet-hub

Terminal

gh attestation verify \
  oci://ghcr.io/kadet-hub/docker@sha256:ef5bfec5d416778a1d9067b0a1666a77c53aa1d1bc76cfbb5f9f7b034a7cd422 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3692459848, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

3Checks kadet-hub

Checked by the release run on , gate at f5400fc049bd.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest v0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Record

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
reclass-rs, omegaconf
With --cache
passed
krab
compatible
Built for (schema-checked)
not recorded
Source
docker-v1.0.2 · docker
Source commit
d2acfd07c1d3a811f012ed0d4046cb2efa8c051c
Binaries
none
Output capabilities
none
Digest
sha256:ef5bfec5d416778a1d9067b0a1666a77c53aa1d1bc76cfbb5f9f7b034a7cd422

Output diff

Fixture output against 1.0.1: 0 files, 0 hunks.

Output diff

1.0.1

1Inventory Your project

Inventory entry

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/docker:1.0.1@sha256:14804771b377d4f60d05a081bfbc33c8daf297cb12eb3d6d6c4b5c3c400733d2
        output_path: lib/docker

2Verify kadet-hub

Terminal

gh attestation verify \
  oci://ghcr.io/kadet-hub/docker@sha256:14804771b377d4f60d05a081bfbc33c8daf297cb12eb3d6d6c4b5c3c400733d2 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

Transparency log: Rekor entry 3228624863, in Sigstore's public, append-only log, so the attestation stays checkable independent of this site.

3Checks kadet-hub

Checked by the release run on , gate at 8332c5f54566.

  • Secrets gitleaks 8.30.1
    No secret matched the marketplace's gitleaks rules.
  • Malware ClamAV 1.5.4
    No file matched a ClamAV signature.
  • Malicious package heuristics GuardDog 3.2.0
    No GuardDog threat rule matched.
  • Dangerous code Semgrep 1.180.0
    No marketplace Semgrep rule matched, such as eval, subprocess or network calls.
  • Python errors Ruff 0.17.0
    No syntax error or undefined name (Ruff, error rules only).
  • File tree tree_check.py
    No symlink, executable or banned file; imports within the allowlist.
  • Sandboxed compile gVisor 20261005, Kapitan 0.36.3
    The fixture compiled without network, with decoy credentials; no undeclared program ran, no decoy was read.
  • Output capabilities Conftest 0.71.1
    The compiled output uses only the capabilities the manifest declares.
  • CI detection Kapitan 0.36.3
    The output is the same with CI variables set.

SBOM (SPDX 2.3)

Record

Kapitan declared
>=0.36.3,<0.37
Kapitan checked
0.36.3
Backends checked
not recorded
With --cache
not recorded
krab
compatible
Built for (schema-checked)
not recorded
Source
docker-v1.0.1 · docker
Source commit
ca05de90ff25a93dc78341b2ab9f1fb7ff09271f
Binaries
none
Output capabilities
none
Digest
sha256:14804771b377d4f60d05a081bfbc33c8daf297cb12eb3d6d6c4b5c3c400733d2

Output diff

No output diff recorded: this version was published before the release run recorded one.