Skip to content

Dockerfiles

The Dockerfile constructor generates a Dockerfile.{name} file alongside docker-compose.yml. The export variable name is used as the suffix.

import { Dockerfile } from "@intentius/chant-lexicon-docker";
export const server = new Dockerfile({
from: "node:20-alpine",
workdir: "/app",
copy: ["package*.json ./"],
run: ["npm ci --only=production"],
copy: ["src/ ./src/"],
user: "node",
expose: [3000],
cmd: `["node", "src/index.js"]`,
});

Produces Dockerfile.server.

export const app = new Dockerfile({
stages: [
{
from: "node:20-alpine",
as: "build",
workdir: "/app",
copy: ["package*.json ./"],
run: ["npm ci"],
copy: ["src/ ./src/"],
run: ["npm run build"],
},
{
from: "node:20-alpine",
workdir: "/app",
copy: ["--from=build /app/dist ./dist", "--from=build /app/node_modules ./node_modules"],
user: "node",
expose: [3000],
cmd: `["node", "dist/index.js"]`,
},
],
});

Produces Dockerfile.app.

FieldDockerfile instruction
fromFROM
asFROM … AS
workdirWORKDIR
runRUN (one instruction per array entry)
copyCOPY
addADD
envENV
argARG
exposeEXPOSE
userUSER
cmdCMD
entrypointENTRYPOINT
labelLABEL
volumeVOLUME
healthcheckHEALTHCHECK

Reference a built image from a Dockerfile entity:

export const api = new Service({
build: { context: ".", dockerfile: "Dockerfile.app" },
ports: ["3000:3000"],
});