You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/containers/local-dev.mdx
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,22 +8,19 @@ sidebar:
8
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.
9
9
10
10
To develop Container-enabled Workers locally, you will need to first ensure that a
11
-
Docker compatible CLI tool and Engine are installed. For instance, you can use [Docker Desktop](https://docs.docker.com/desktop/)
12
-
on Mac, Windows, or Linux.
11
+
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).
13
12
14
-
When you run `wrangler dev`, your container image will be built or downloaded. If your
the `image` attribute to a local path, the image will be built using the local Dockerfile.
17
16
If the `image` attribute is set to a URL, the image will be pulled from the associated registry.
18
17
19
18
Container instances will be launched locally when your Worker code calls to create
20
19
a new container. This may happen when calling `.get()` on a `Container` instance or
21
-
by calling `start()` if `manualStart` is set to `true`. Wrangler will
22
-
boot new instances and automatically route requests to the correct local container.
20
+
by calling `start()` if `manualStart` is set to `true`. Requests will then automatically be routed to the correct locally-running container.
23
21
24
-
When `wrangler dev` stops, all associated container instances are stopped, but
25
-
local images are not removed, so that they can be reused in subsequent calls to
26
-
`wrangler dev` or `wrangler deploy`.
22
+
When the dev session ends, all associated container instances should be stopped, but
23
+
local images are not removed, so that they can be reused in subsequent builds.
27
24
28
25
:::note
29
26
If your Worker app creates many container instances, your local machine may not be able to run as many containers concurrently as is possible when you deploy to Cloudflare.
@@ -36,23 +33,22 @@ Also note that the `max_instances` configuration option is only enforced when ru
36
33
37
34
## Iterating on Container code
38
35
39
-
When you use `wrangler dev`, your Worker's code is automatically reloaded by Wrangler each time you save a change,
36
+
When you develop with Wrangler or Vite, your Worker's code is automatically reloaded each time you save a change,
40
37
but code running within the container is not.
41
38
42
39
To rebuild your container with new code changes, you can hit the `[r]` key on your keyboard, which
43
40
triggers a rebuild. Container instances will then be restarted with the newly built images.
44
41
45
42
You may prefer to set up your own code watchers and reloading mechanisms, or mount a local directory
46
43
into the local container images to sync code changes. This can be done, but there is no built-in
47
-
mechanism for doing so in Wrangler, and best-practices will depend on the languages and frameworks
44
+
mechanism for doing so here, and best-practices will depend on the languages and frameworks
48
45
you are using in your container code.
49
46
50
47
## Troubleshooting
51
48
52
49
### Exposing Ports
53
50
54
-
In production, all of your container's ports will be accessible by your Worker,
55
-
so you do not need to specifically expose ports using the [`EXPOSE` instruction](https://docs.docker.com/reference/dockerfile/#expose) in your Dockerfile.
51
+
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.
56
52
57
53
But for local development you will need to declare any ports you need to access in your Dockerfile with the EXPOSE instruction; for example: `EXPOSE 4000`, if you will be accessing port 4000.
58
54
@@ -70,3 +66,7 @@ connect(): Connection refused: container port not found. Make sure you exposed t
70
66
71
67
You may also see this while the container is starting up and no ports are available yet. You should retry until the ports become available.
72
68
This retry logic should be handled for you if you are using the [containers package](https://github.com/cloudflare/containers/tree/main/src).
69
+
70
+
### Socket configuration - `internal error`
71
+
72
+
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.
- Defaults to `unix:///var/run/docker.sock`. Set this to the socket path your container engine is listening at if you are using another container tool besides Docker, such as `colima`, or if your Docker engine is configured to listen at a path other than `unix:///var/run/docker.sock`. You can also set this via the environment variable `WRANGLER_DOCKER_HOST`.
1234
-
1235
-
Example:
1233
+
- Used for local development of [Containers](/containers/local-dev). Wrangler will attempt to automatically find the correct socket to use to communicate with your container engine. If that does not work (usually surfacing as an `internal error` when attempting to connect to your Container), you can try setting the socket path using this option. You can also set this via the environment variable `DOCKER_HOST`.
System environment variables are local environment variables that can change Wrangler's behavior. There are three ways to set system environment variables:
12
11
@@ -25,54 +24,49 @@ To set different system environment variables for each environment, create files
25
24
26
25
Wrangler supports the following environment variables:
* The [API token](/fundamentals/api/get-started/create-token/) for your Cloudflare account, can be used for authentication for situations like CI/CD, and other automation.
* The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`.
33
+
- The [API token](/fundamentals/api/get-started/create-token/) for your Cloudflare account, can be used for authentication for situations like CI/CD, and other automation.
* Options for this are `true` and `false`. Defaults to `true`. Controls whether Wrangler can send anonymous usage data to Cloudflare for this project. You can learn more about this in our [data policy](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md).
41
+
- The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`.
* The [local connection string](/hyperdrive/configuration/local-development/) for your database to use in local development with [Hyperdrive](/hyperdrive/). For example, if the binding for your Hyperdrive is named `PROD_DB`, this would be `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_PROD_DB="postgres://user:[email protected]:5432/testdb"`. Each Hyperdrive is uniquely distinguished by the binding name.
45
+
- Options for this are `true` and `false`. Defaults to `true`. Controls whether Wrangler can send anonymous usage data to Cloudflare for this project. You can learn more about this in our [data policy](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md).
* The default value is `"https://api.cloudflare.com/client/v4"`.
49
+
- The [local connection string](/hyperdrive/configuration/local-development/) for your database to use in local development with [Hyperdrive](/hyperdrive/). For example, if the binding for your Hyperdrive is named `PROD_DB`, this would be `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_PROD_DB="postgres://user:[email protected]:5432/testdb"`. Each Hyperdrive is uniquely distinguished by the binding name.
* Options for Logging levels are `"none"`, `"error"`, `"warn"`, `"info"`, `"log"` and `"debug"`. Levels are case-insensitive and default to `"log"`. If an invalid level is specified, Wrangler will fallback to the default. Logs can include requests to Cloudflare's API, any usage data being collected, and more verbose error logs.
53
+
- The default value is `"https://api.cloudflare.com/client/v4"`.
* A file or directory path where Wrangler will write debug logs. If the path ends in `.log`, Wrangler will consider this the path to a file where all logs will be written. Otherwise, Wrangler will treat the path as a directory where it will write one or more log files using a timestamp for the filenames.
57
+
- Options for Logging levels are `"none"`, `"error"`, `"warn"`, `"info"`, `"log"` and `"debug"`. Levels are case-insensitive and default to `"log"`. If an invalid level is specified, Wrangler will fallback to the default. Logs can include requests to Cloudflare's API, any usage data being collected, and more verbose error logs.
* By setting this to `0`, you can disable Wrangler's colorised output, which makes it easier to read with some terminal setups. For example, `FORCE_COLOR=0`.
61
+
- A file or directory path where Wrangler will write debug logs. If the path ends in `.log`, Wrangler will consider this the path to a file where all logs will be written. Otherwise, Wrangler will treat the path as a directory where it will write one or more log files using a timestamp for the filenames.
* Defaults to `unix:///var/run/docker.sock`. Set this to the socket path your container engine is listening at if you are using another container tool besides Docker, such as `colima`, or if your Docker engine is configured to listen at a path other than `unix:///var/run/docker.sock`.
73
-
You can also set this via `container_engine` config option.
65
+
- By setting this to `0`, you can disable Wrangler's colorised output, which makes it easier to read with some terminal setups. For example, `FORCE_COLOR=0`.
- Used for local development of [Containers](/containers/local-dev). Wrangler will attempt to automatically find the correct socket to use to communicate with your container engine. If that does not work (usually surfacing as an `internal error` when attempting to connect to your Container), you can try setting the socket path using this environment variable.
0 commit comments