A minimal Worker whose Durable Objects start namespace-backed containers on demand.
- Node.js 22 or newer, pnpm 10.33.0, and Docker
- A Cloudflare account with Workers, Containers, and the new runtime enabled.
Wrangler is pinned to the published 4.132.0 release in package.json and the lockfile. All package scripts use that local version.
Install dependencies and verify the CLI version:
pnpm install
pnpm exec wrangler --versionCheck the generated bindings, TypeScript, and Worker bundle locally:
pnpm check
pnpm deploy:dryCheck your account, then deploy. Run pnpm exec wrangler login first if you are not already logged in:
pnpm exec wrangler whoami
pnpm run deployWrangler builds and pushes the image, prepares it to run on Cloudflare, uploads the Worker, and creates the namespace-backed application if it is missing. Normal deploys apply explicitly configured application settings; omitted settings are preserved.
Use the Worker URL printed by Wrangler:
curl "https://<worker-url>/?instance=first"
curl "https://<worker-url>/_status?instance=first"
curl "https://<worker-url>/_destroy?instance=first"Each instance value selects a different Durable Object and container.
- The existing
v1migration declares the SQLite-backedSandboxclass.containers[].class_nameattaches its container. scheduling_policy: "durable_object"makes each Durable Object own its container lifecycle.- The named
images.appconfiguration usesdockerfile: "./container/Dockerfile"andbuild_context: "./container". Wrangler builds, pushes, and prepares that image. The Dockerfile'sCOPYinstructions resolve against the container directory. Per-imagebuild_varscan supply Docker build arguments when needed; this Dockerfile requires none. - The Worker reads the resolved image from
this.ctx.container.images.appand passes it tocontainer.start(). - Instance size, entrypoint, environment, and inactivity timeout are set in
src/index.tsat runtime. - Top-level
observabilityenables Worker logs. Container application logs are configured separately withcontainers[].observability; omitting that setting preserves the application's existing configuration.