npm add docker-client-tsimport { DockerClient } from "docker-client-ts";
const client = await DockerClient({
baseURL: new URL("unix:/var/run/docker.sock"),
ssh: {
user: "username",
host: "127.0.0.1",
port: 22,
key: Buffer.from("ssh private key", "utf8"),
},
});
const { Id } = await client.Container.Create({
body: {
Image: "debian",
Cmd: ["bash"],
Tty: true,
},
});
await client.Container.Start({
path: { id: Id },
});see tests for more example usage
npm run generate fetches the Docker Engine API
and Compose Specification schemas and normalizes
them into a single data module, src/spec.ts. Nothing is code generated — that one as const
object is the only source of truth, and it is read twice:
- at runtime, by zod's
fromJSONSchema, to validate responses - at compile time, by
json-schema-to-ts'sFromSchema, to type the client
so the validation and the types cannot drift apart.
Schemas are converted lazily and memoized, so a client only pays for the operations it calls. Every operation's schemas are reachable if you need them directly:
import { type OperationError, ops, toZod } from "docker-client-ts";
const LogsError = toZod<OperationError<"Container", "Logs">>(ops.Container.Logs.output.error);OperationInput and OperationOutput are available the same way.