You can run both your container and your Worker locally by running npx wrangler dev (or vite dev for Vite projects using the Cloudflare Vite plugin) in your project's directory.
To develop Container-enabled Workers locally, you will need to first ensure that a Docker compatible CLI tool and Engine are installed. For instance, you could use Docker Desktop ↗︎ or Colima ↗︎.
Containers that use the Durable Object scheduling policy require Wrangler 4.136.0 or later for local development. To run the cloudflare/debian-trixie managed image locally, use Wrangler 4.141.0 or later.
When you start a dev session, your container image will be built or downloaded. If your
Wrangler configuration sets
the image attribute to a local path, the image will be built using the local Dockerfile.
If the image attribute is set to an image reference, the image will be pulled from the referenced registry, such as the Cloudflare Registry, Docker Hub, Amazon ECR, or Google Artifact Registry.
Container instances will be launched locally when your Worker code calls to create a new container. Requests will then automatically be routed to the correct locally-running container.
To receive raw TCP connections locally, export a connect() handler and configure a TCP listener in wrangler.jsonc:
{
"connect": [{ "protocol": "tcp", "port": 8788 }],
}[[connect]]
protocol = "tcp"
port = 8_788Connect TCP or gRPC clients to localhost:8788. The port comes from this configuration; exporting the handler alone does not create a listener.
Refer to Bidirectional gRPC with Workers and Containers for a complete local development workflow.
When the dev session ends, all associated container instances should be stopped, but local images are not removed, so that they can be reused in subsequent builds.
Miniflare automatically grants local containers the Docker privileges required for Filesystem in Userspace (FUSE). This applies to wrangler dev, the Cloudflare Vite plugin, and direct Miniflare use.
Miniflare grants these privileges when the local Docker daemon runs inside a virtual machine (VM). This includes Docker engines on macOS and through Windows Subsystem for Linux (WSL). On Linux, Miniflare grants the privileges for local rootless Docker when /dev/fuse is available.
Rootful Docker on Linux does not support FUSE by default during local development. Miniflare does not grant FUSE privileges when the Docker daemon does not meet these conditions or cannot be inspected.
When you develop with Wrangler or Vite, your Worker's code is automatically reloaded each time you save a change, but code running within the container is not.
To rebuild your container with new code changes, you can hit the [r] key on your keyboard, which
triggers a rebuild. Container instances will then be restarted with the newly built images.
You may prefer to set up your own code watchers and reloading mechanisms, or mount a local directory into the local container images to sync code changes. This can be done, but there is no built-in mechanism for doing so, and best-practices will depend on the languages and frameworks you are using in your container code.
Local development runs your container in Docker. A deployed container that uses the Durable Object scheduling policy grants Linux capabilities differently from a local container. Code that works locally can fail after you deploy.
Locally, Docker gives no capabilities to a process that runs as a user other than root. File permissions apply to that process. In a deployed container, every process has the same Linux capabilities as root, regardless of user. For more information, refer to the exec() user option.
Your Worker can connect to any port in the container.
getTcpPort() requires a process listening on that port. If the process has not started yet, you will see the following error:
Container is not listening to port 8080Retry until the port becomes available.
If you see an opaque internal error when attempting to connect to your container, you may need to set the DOCKER_HOST environment variable to the socket path your container engine is listening on. Wrangler or Vite will attempt to automatically find the correct socket to use to communicate with your container engine, but if that does not work, you may have to set this environment variable to the appropriate socket path.
If you are running the Cloudflare One Client or a VPN that performs TLS inspection, HTTPS requests made during the Docker build process may fail with SSL or certificate errors. This happens because the VPN intercepts HTTPS traffic and re-signs it with its own certificate authority, which Docker does not trust by default.
To resolve this, you can either:
-
Disable the Cloudflare One Client or your VPN while running
wrangler devorwrangler deploy, then re-enable it afterwards. -
Add the certificate to your Docker build context. The Cloudflare One Client exposes its certificate via the
NODE_EXTRA_CA_CERTSandSSL_CERT_FILEenvironment variables on your host machine. You can pass the certificate into your Docker build as an environment variable, so that it is available during the build without being baked into the final image.RUN if [ -n "$SSL_CERT_FILE" ]; then \ cp "$SSL_CERT_FILE" /usr/local/share/ca-certificates/Custom_CA.crt && \ update-ca-certificates; \ fiWrangler invokes Docker automatically when you run
wrangler devorwrangler deploy, so if you need to pass build secrets, you will need to build and push the image manually usingwrangler containers push.