Use Containers in a Worker
Containers let a Worker hand requests to stateful code running from a container image.
Add the Containers config, call Container class config plus a Durable Object container binding from worker code, and start with the local test path Devflare supports.
Start with the config, wire the binding into worker code, then use the support section to decide whether local tests or Cloudflare-backed tests fit.
- Config key
- Authoring shape
- Best for
- routing requests to a stateful container instance that runs code outside the Workers runtime
Use the binding from application code
After Devflare generates the worker env, import from and keep the first Containers path close to the route, handler, or service method that needs it.
Keep this first path small enough that the config, env binding, and user-visible behavior are easy to review together.
Proxy one application route to a container instance
Local and Remote Support
Devflare can run useful Containers application behavior locally for ordinary development and tests. Cloudflare still owns production limits, quotas, billing, and deployed account behavior.
Containers have full local support when Docker or Podman is reachable and the image can be built or inspected without Cloudflare. Devflare builds Dockerfile paths offline-first, runs the container on loopback, and exposes fetch, logs, state, stop, and destroy helpers. Cloudflare still owns deployed rollout, registry availability, SSH, scaling, and hosted platform behavior.
Use Cloudflare when the assertion depends on deployed limits, account state, lifecycle behavior, billing, or other production-only Containers details.
Let the Durable Object choose the image: the durable_object scheduling policy
Cloudflare's scheduling policy (public beta) moves the image and instance size out of config and into . Cloudflare's scheduling-policy page marks the older policy deprecated, and its 2026-09-30 announcement says the class gets no updates after 2026-12-31, so new containers should use this one. The policy is immutable per application: moving an existing application means a new one.
Set and list the images the object may start under . Each key becomes a property of . Devflare compiles the entry to Wrangler's , , and and nothing else, because Wrangler rejects , , and rollouts for this policy; the schema refuses them first.
and run it locally the way does: they build each Dockerfile image (or reuse or pull a registry image) with Docker or Podman for , pull Miniflare's egress interceptor image, and attach the container to the Durable Object in Miniflare. , , and the , and rules then run against a real local container.
- A named image is either or , a digest-pinned . Between 1 and 100 images, each name 1 to 128 characters.
- The Durable Object class must use SQLite storage. List it in ; local runs give container-backed namespaces SQLite storage, as Wrangler does.
- Outbound intercepts target a through , which needs a compatibility date of 2025-11-17 or later. In , the classes exported from the Durable Object's own module are exported from the test gateway, so resolves there too. A service binding also works as a target.
- HTTPS interception needs the container to trust .
- Local runs need Linux or macOS: workerd cannot reach a Windows named pipe, so on Windows devflare refuses and points at WSL, as Wrangler does. Set to start without containers; is then undefined. Devflare uses or when set, then the engine's own socket.
- does not run durable_object containers yet and refuses an app that declares one; run in that app. The helper starts only -policy containers.
- A worker this one only references runs its containers too. Through a service binding to it, in and in , or through a cross-worker Durable Object binding to its class, in , devflare builds its images from its own config and attaches them where it hosts that Durable Object. So once a worker references one with a container, those runs need an engine (and on Windows, WSL or ) even when its own config declares none.
- The Vite plugin ( of a SvelteKit app) does not attach a referenced worker's containers, so is undefined in it there. The path above is tested for a worker-only project; test a SvelteKit app's call into such a worker with . refuses an app that reaches one through a service binding.
- Images are rebuilt each time the config loads; a change inside the container needs a restart.
Declare a Durable Object-managed container
Start it from the Durable Object, with the Internet off and one host allowed
What it compiles to
Build and reference the image deliberately
Devflare treats the entry as the contract between the Worker class and a real container image. For local work, point at a tag that already exists in Docker or Podman, or point it at a local Dockerfile path that Devflare can build from files on disk.
Cloudflare uses the same container idea in the hosted lane: Wrangler accepts a Dockerfile path or an image reference. Dockerfile paths are built locally and pushed during deploy, while image references can come from the Cloudflare Registry, Docker Hub, or Amazon ECR.
- Use or when you want Wrangler deploy to build and push from source.
- Use for a local tag that Docker or Podman can inspect without a network pull.
- Use for Cloudflare Registry images, Docker Hub names such as , or Amazon ECR image references when the hosted deploy should pull a prebuilt image.
- Use when the image lives in a private external registry.
Build the local image with Docker or Podman
Reference that local image from Devflare config
Use a Dockerfile or registry image for the Cloudflare lane
Full local support requirements
Full local support means Devflare can build, launch, call, inspect, and clean up the container without Cloudflare when the local machine has a working Docker or Podman engine.
The offline-first default is strict: Dockerfile builds use cached base layers, and image references must already exist locally. Set only when the test is allowed to pull from a registry.
- Install Docker or Podman and make sure or succeeds before running container tests.
- Set for test lanes that are allowed to start local containers.
- Gate CI and hosted runners with because GitHub Actions, Cloudflare runners, and preview workers may not expose a usable container engine.
- Keep base images cached when running offline. A missing local tag or uncached base layer is a setup problem, not a reason to silently reach out to a registry.
Run a container-backed route test only when the engine is available
When this binding fits best
- Use Containers when routing requests to a stateful container instance that runs code outside the workers runtime.
- Keep binding names stable and uppercase in examples so generated Env declarations remain predictable.
- Prefer Devflare native config while it covers the feature; use only for unsupported Wrangler-only fields.
Testing path
- Start with containers helpers guarded by for config-backed local worker tests.
- Use / / for small unit tests that only need deterministic application behavior.
- Use Cloudflare-backed tests when the assertion depends on hosted platform behavior, account state, limits, billing, or production routing.
Open the next page when you need it
Subpage
Containers internals
InternalsCheck emitted Wrangler , preview behavior, and Cloudflare-specific details.
Subpage
Testing Containers
TestingPick the containers helpers guarded by path first, then move to remote checks only when the test needs them.
Subpage
Containers example
ExampleCopy a fuller application path when the quick example is too small.