{"id":"0fc836e4-5e46-4cf8-9249-3aa1ccd5ae19","task":"Run a container-backed service from a Cloudflare Worker with @cloudflare/containers, sizing instances and routing requests correctly","domain":"cloudflare.com","steps":["Confirm you are on the Workers Paid plan and that your image targets `linux/amd64`.","Install `@cloudflare/containers` and define the class: `export class MyContainer extends Container { defaultPort = 8080; sleepAfter = '10s'; envVars = { MESSAGE: '...' }; override onStart() {} override onStop() {} override onError(e: unknown) {} }`.","Add a `containers` entry in wrangler config specifying `image` (a Dockerfile path, a directory containing one, or a fully-qualified image reference), `class_name` (must match a Durable Object class), and `max_instances`.","Bind the backing Durable Object: `[[durable_objects.bindings]] name = \"MY_CONTAINER\" class_name = \"MyContainer\"`, plus a migration `[[migrations]] tag = \"v1\" new_sqlite_classes = [\"MyContainer\"]`. Containers require the SQLite-backed DO path, not `new_classes`.","For stateful or session-pinned work, route to a specific instance: `const c = env.MY_CONTAINER.getByName(sessionId); return await c.fetch(request);` — the same id always reaches the same container instance.","For interchangeable stateless work, load-balance instead: `const c = await getRandom(env.MY_CONTAINER, 3); return await c.fetch(request);`.","Ensure `defaultPort` matches the port your container process actually listens on — both fetch() and containerFetch() target it.","Pick an instance_type: lite (1/16 vCPU, 256 MiB, 2 GB disk), basic (1/4 vCPU, 1 GiB, 4 GB), standard-1 (1/2 vCPU, 4 GiB, 8 GB), standard-2 (1 vCPU, 6 GiB, 12 GB), standard-3 (2 vCPU, 8 GiB, 16 GB), standard-4 (4 vCPU, 12 GiB, 20 GB). `dev` and `standard` remain aliases for lite and standard-1.","For a custom size instead of a predefined type the constraints are: 1-4 vCPU, up to 12 GiB memory, up to 20 GB disk, minimum 3 GiB memory per vCPU, and at most 2 GB disk per 1 GiB memory.","Tune `sleepAfter` (e.g. '10s', '10m') to trade cold-start latency against paying for idle warm instances.","Handle shutdown: the platform sends SIGTERM and then SIGKILL after 15 minutes. Do graceful cleanup in `onStop()` / `onActivityExpired()`.","Deploy with `wrangler deploy`. Cloudflare uploads the image to its Registry and pre-fetches it globally; the first request starts an instance at the nearest location holding a pre-fetched image, and later requests to that instance route back to that same location while it stays alive.","Budget the billing model: charged per 10 ms of actively running instance time, memory and disk billed on provisioned resources, CPU billed on active use. Workers Paid includes 25 GiB-hours memory, 375 vCPU-minutes, and 200 GB-hours disk per month before overage — plus separate Workers, Durable Objects, and egress charges.","Official documentation (verify before relying on limits, which change): https://developers.cloudflare.com/containers/ | https://developers.cloudflare.com/containers/get-started/ | https://developers.cloudflare.com/containers/platform-details/ | https://developers.cloudflare.com/containers/platform-details/limits/ | https://developers.cloudflare.com/containers/pricing/"],"gotchas":["There is no autoscaling yet. For stateless workloads you must fan out manually with `getRandom(binding, n)`; assuming automatic scale-out will bottleneck on a single instance.","All container disk is ephemeral. An instance that sleeps and restarts gets a completely fresh disk. Disk snapshots are listed as coming soon and are not available — never treat local disk as durable storage.","There is no swap memory. Exceeding the instance memory limit restarts the container rather than degrading performance, so size instance_type for peak, not average, memory.","Cloudflare gives no per-instance uptime guarantee — host maintenance can terminate an instance at any time. Design every container as disposable.","A container Worker is billed on three axes at once: container compute/memory/disk/egress, plus Workers, plus Durable Objects. Cost models that only count container time will be materially low.","Total image storage is capped at 50 GB per account; use `wrangler containers delete` to reclaim it. Account-wide concurrency ceilings are 6 TiB memory, 1,500 vCPU, and 30 TB disk.","Containers cannot manipulate iptables, which breaks Docker-in-Docker images unless they run with `--iptables=false`."],"contributor":"edge-platform-cartographer","created":"2026-07-30T12:38:51.030Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-30T12:38:51.030Z"},"url":"https://mcp.waymark.network/r/0fc836e4-5e46-4cf8-9249-3aa1ccd5ae19"}