Skip to content

Cluster.Docker reference

Source: packages/effect-cluster/src/Docker/Database.ts

The database an Effect Cluster coordinates through, on a Docker swarm, as an Cluster.Database Layer: Postgres as a one-replica swarm service with its data on a named volume, on an overlay network the pool’s runners join. The Docker engine must be in swarm mode (docker swarm init).

One Postgres on one disk is meant for development and tests.

export const Database = ClusterDocker.Database("Cluster");

Source: packages/effect-cluster/src/Docker/SwarmPool.ts

Run a pool of Effect Cluster runners on a Docker swarm: a swarm service whose tasks host every Cluster.Entity given this pool, on the database’s overlay network. Runners find each other through the database and talk on the network; the gateway is served on the same network. With a database on no Docker network (Cluster.Database.fromUrl), runners join the pool’s network, or an overlay network of its own.

Every entity given the same pool shares it: declare the pool once and provide them to each class.

export const Database = ClusterDocker.Database("Cluster");
export const Default = ClusterDocker.SwarmPool("Default", { replicas: 2 }).pipe(
Layer.provide(Database),
);

SwarmPool: Using a database you already run

Section titled “SwarmPool: Using a database you already run”

Runners on their own network, connecting to Postgres by URL

export const Database = Cluster.Database.fromUrl({
url: Config.Redacted("CLUSTER_DATABASE_URL"),
});
export const Default = ClusterDocker.SwarmPool("Default").pipe(
Layer.provide(Database),
);

Runners on a remote engine, trusting a private CA

export const Default = ClusterDocker.SwarmPool("Default", {
// A Docker context on this machine, e.g. `docker context create vps --docker host=ssh://deploy@vps`.
context: "vps",
dockerfile: [
"FROM node:26-slim",
"WORKDIR /app",
"COPY *.mjs /app/",
"ADD https://pki.example.com/root-ca.pem /etc/ssl/db-ca.pem",
"ENV NODE_EXTRA_CA_CERTS=/etc/ssl/db-ca.pem NODE_ENV=production",
'ENTRYPOINT ["node", "/app/runner.mjs"]',
].join("\n"),
}).pipe(Layer.provide(Database));