Skip to content

Commit 7e06b7c

Browse files
Update local-dev.mdx
Main Changes: 1. Added "Required Configuration" section - Shows the complete wrangler.json structure needed for local development 2. Clarified required fields: - name field in container config - instance_type field (typically "standard") - nodejs_compat compatibility flag 3. Added troubleshooting note - Explains that missing these fields causes "Connection refused" errors 4. Removed misleading phrase - Changed "without additional configuration" to just describing how to run the commands The updated documentation now accurately reflects what's actually needed to get containers working locally, preventing the issues we encountered. This should help other developers avoid the debugging session we just went through!
1 parent 5051178 commit 7e06b7c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/content/docs/containers/local-dev.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@ sidebar:
55
order: 3
66
---
77

8-
You can run both your container and your Worker locally, without additional configuration, by running [`npx wrangler dev`](/workers/wrangler/commands/#dev) (or `vite dev` for Vite projects using the [Cloudflare Vite plugin](/workers/vite-plugin/)) in your project's directory.
8+
You can run both your container and your Worker locally by running [`npx wrangler dev`](/workers/wrangler/commands/#dev) (or `vite dev` for Vite projects using the [Cloudflare Vite plugin](/workers/vite-plugin/)) in your project's directory.
99

1010
To develop Container-enabled Workers locally, you will need to first ensure that a
1111
Docker compatible CLI tool and Engine are installed. For instance, you could use [Docker Desktop](https://docs.docker.com/desktop/) or [Colima](https://github.com/abiosoft/colima).
1212

13+
## Required Configuration
14+
15+
For local development, your `wrangler.json` or `wrangler.jsonc` file must include specific configuration fields:
16+
17+
```json
18+
{
19+
"containers": [{
20+
"name": "your-container-name", // Required for local development
21+
"class_name": "YourContainerClass", // Your Durable Object class name
22+
"image": "./path/to/Dockerfile", // Path to your Dockerfile
23+
"instance_type": "standard", // Required for proper runtime behavior
24+
"max_instances": 2 // Optional, not enforced locally
25+
}],
26+
"compatibility_flags": ["nodejs_compat"] // Required when using Container class from @cloudflare/containers
27+
}
28+
```
29+
30+
:::note
31+
The `name` and `instance_type` fields are essential for local development. Without them, you may encounter "Connection refused: container port not found" errors even if your container is properly configured.
32+
:::
33+
1334
When you start a dev session, your container image will be built or downloaded. If your
1435
[Wrangler configuration](/workers/wrangler/configuration/#containers) sets
1536
the `image` attribute to a local path, the image will be built using the local Dockerfile.
@@ -46,6 +67,15 @@ you are using in your container code.
4667

4768
## Troubleshooting
4869

70+
### Container Configuration Errors
71+
72+
If you encounter "Connection refused: container port not found" errors during local development, verify that:
73+
74+
1. Your container configuration includes a `name` field
75+
2. Your container configuration includes an `instance_type` field (typically `"standard"`)
76+
3. You have `nodejs_compat` in your `compatibility_flags` array if using the Container class from `@cloudflare/containers`
77+
4. Your Dockerfile includes the necessary `EXPOSE` instructions (see below)
78+
4979
### Exposing Ports
5080

5181
In production, all of your container's ports will be accessible by your Worker, so you do not need to specifically expose ports using the [`EXPOSE` instruction](https://docs.docker.com/reference/dockerfile/#expose) in your Dockerfile.

0 commit comments

Comments
 (0)