Skip to content
Source
Sign inSign up

.repos/alchemy-effect/packages/docker

Contents of .repos/alchemy-effect/packages/docker
NameLast commit messageLast commit date
..
scripts (directory)
src (directory)
package.json
README.md
tsconfig.json

README.md

@alchemy.run/docker

Docker for Alchemy. Declare images, containers, networks, and volumes as typed resources, driven through your active Docker context. Other Alchemy providers use it to build and push the images they deploy.

npm install alchemy @alchemy.run/docker effect

A local Postgres with a generated password, a network, and a data volume:

// alchemy.run.ts
import * as Alchemy from "alchemy";
import * as Docker from "@alchemy.run/docker";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";

export default Alchemy.Stack(
  "MyApp",
  {
    providers: Layer.merge(Docker.providers(), Alchemy.RandomProvider()),
    state: Alchemy.localState(),
  },
  Effect.gen(function* () {
    const password = yield* Alchemy.makeRandom("PostgresPassword", { bytes: 16 });
    const image = yield* Docker.RemoteImage("Postgres", { name: "postgres", tag: "18-alpine" });
    const network = yield* Docker.Network("Network");
    const data = yield* Docker.Volume("Data");

    const postgres = yield* Docker.Container("Db", {
      image,
      environment: { POSTGRES_PASSWORD: password },
      ports: [{ external: 15432, internal: 5432 }],
      volumes: [{ hostPath: data.name, containerPath: "/var/lib/postgresql/data" }],
      networks: [{ name: network.name, aliases: ["postgres"] }],
      start: true,
    });

    return { container: postgres.name };
  }),
);

alchemy deploy pulls the image and starts the container. Change a prop and the next deploy replaces only what changed; alchemy destroy removes all of it.

Learn more