Serialization
The Docker lexicon serializes to two output formats.
docker-compose.yml
Section titled “docker-compose.yml”chant build src --lexicon docker -o docker-compose.ymlEach entity type maps to a top-level Compose section. The TypeScript export name becomes the key within that section.
export const db = new Service({ image: "postgres:16-alpine" });export const pgdata = new Volume({});export const backend = new Network({ driver: "bridge" });Produces:
services: db: image: postgres:16-alpine
volumes: pgdata: null
networks: backend: driver: bridgedefaultLabels() entities are not emitted as separate keys — their labels are merged into each service.
Dockerfile.{name}
Section titled “Dockerfile.{name}”chant build src --lexicon docker# Writes Dockerfile.app, Dockerfile.builder, etc.Each Dockerfile entity produces a separate file. The export name is the suffix.
export const builder = new Dockerfile({ from: "node:20-alpine", ... });// → Dockerfile.builderField mapping
Section titled “Field mapping”| TypeScript | docker-compose.yml | Notes |
|---|---|---|
env("X", { required: true }) | ${X:?X is required} | Compose interpolation |
env("X", { default: "v" }) | ${X:-v} | Compose interpolation |
env("X") | ${X} | Compose interpolation |
external: true | external: true | Volume/Network |
Specifying lexicon at build time
Section titled “Specifying lexicon at build time”The --lexicon docker flag restricts output to Docker entities only — useful in mixed-lexicon projects:
# Only Docker outputchant build src --lexicon docker -o docker-compose.yml
# Other lexicons still get their own outputschant build src --lexicon aws -o template.json