Skip to content

Serialization

The Docker lexicon serializes to two output formats.

Terminal window
chant build src --lexicon docker -o docker-compose.yml

Each 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: bridge

defaultLabels() entities are not emitted as separate keys — their labels are merged into each service.

Terminal window
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.builder
TypeScriptdocker-compose.ymlNotes
env("X", { required: true })${X:?X is required}Compose interpolation
env("X", { default: "v" })${X:-v}Compose interpolation
env("X")${X}Compose interpolation
external: trueexternal: trueVolume/Network

The --lexicon docker flag restricts output to Docker entities only — useful in mixed-lexicon projects:

Terminal window
# Only Docker output
chant build src --lexicon docker -o docker-compose.yml
# Other lexicons still get their own outputs
chant build src --lexicon aws -o template.json