@alchemy.run/docker (中文(简体) )
挂起点 炼金术。将图像、容器、网络和卷作为已键入的资源,通过您正在运行的 Docker 上下文驱动。 其他的炼金术提供商利用它来构建并推进它们所部署的图像.
npm install alchemy @alchemy.run/docker effect
本地 Postgres 有生成的密码、网络和数据卷 :
// 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 拖动图像并启动容器。 改变道具,下一次部署只取代改变的东西; alchemy destroy 取出一切诸相.