Skip to content

Commit afdfb6e

Browse files
emily-shenthomasgauvin
authored andcommitted
update containers local dev socket configuration docs (#23963)
* updates to socket configuration docs * update wording
1 parent 6a239a4 commit afdfb6e

File tree

3 files changed

+45
-65
lines changed

3 files changed

+45
-65
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@ sidebar:
88
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.
99

1010
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).
1312

14-
When you run `wrangler dev`, your container image will be built or downloaded. If your
15-
[wrangler configuration](/workers/wrangler/configuration/#containers) sets
13+
When you start a dev session, your container image will be built or downloaded. If your
14+
[Wrangler configuration](/workers/wrangler/configuration/#containers) sets
1615
the `image` attribute to a local path, the image will be built using the local Dockerfile.
1716
If the `image` attribute is set to a URL, the image will be pulled from the associated registry.
1817

1918
Container instances will be launched locally when your Worker code calls to create
2019
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.
2321

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.
2724

2825
:::note
2926
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
3633

3734
## Iterating on Container code
3835

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,
4037
but code running within the container is not.
4138

4239
To rebuild your container with new code changes, you can hit the `[r]` key on your keyboard, which
4340
triggers a rebuild. Container instances will then be restarted with the newly built images.
4441

4542
You may prefer to set up your own code watchers and reloading mechanisms, or mount a local directory
4643
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, and best-practices will depend on the languages and frameworks
4845
you are using in your container code.
4946

5047
## Troubleshooting
5148

5249
### Exposing Ports
5350

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.
5652

5753
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.
5854

@@ -70,3 +66,7 @@ connect(): Connection refused: container port not found. Make sure you exposed t
7066

7167
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.
7268
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.

src/content/docs/workers/wrangler/configuration.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,8 @@ You can configure various aspects of local development, such as the local protoc
12301230

12311231
- `container_engine` <Type text="string" /> <MetaInfo text="optional" />
12321232

1233-
- 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`.
1234+
Example:
12361235

12371236
<WranglerConfig>
12381237

src/content/docs/workers/wrangler/system-environment-variables.mdx

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ pcx_content_type: configuration
33
title: System environment variables
44
head: []
55
description: Local environment variables that can change Wrangler's behavior.
6-
76
---
87

9-
import { Render, Type, MetaInfo } from "~/components"
8+
import { Render, Type, MetaInfo } from "~/components";
109

1110
System environment variables are local environment variables that can change Wrangler's behavior. There are three ways to set system environment variables:
1211

@@ -25,62 +24,44 @@ To set different system environment variables for each environment, create files
2524

2625
Wrangler supports the following environment variables:
2726

27+
- `CLOUDFLARE_ACCOUNT_ID` <Type text="string" /> <MetaInfo text="optional" />
28+
- The [account ID](/fundamentals/account/find-account-and-zone-ids/) for the Workers related account.
2829

30+
- `CLOUDFLARE_API_TOKEN` <Type text="string" /> <MetaInfo text="optional" />
31+
- 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.
2932

30-
* `CLOUDFLARE_ACCOUNT_ID` <Type text="string" /> <MetaInfo text="optional" />
31-
32-
* The [account ID](/fundamentals/account/find-account-and-zone-ids/) for the Workers related account.
33-
34-
* `CLOUDFLARE_API_TOKEN` <Type text="string" /> <MetaInfo text="optional" />
35-
36-
* 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.
37-
38-
* `CLOUDFLARE_API_KEY` <Type text="string" /> <MetaInfo text="optional" />
39-
40-
* The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`.
41-
42-
* `CLOUDFLARE_EMAIL` <Type text="string" /> <MetaInfo text="optional" />
43-
44-
* The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`.
45-
46-
* `WRANGLER_SEND_METRICS` <Type text="string" /> <MetaInfo text="optional" />
33+
- `CLOUDFLARE_API_KEY` <Type text="string" /> <MetaInfo text="optional" />
34+
- The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`.
4735

48-
* 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).
36+
- `CLOUDFLARE_EMAIL` <Type text="string" /> <MetaInfo text="optional" />
37+
- The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`.
4938

50-
* `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`<Type text="string" /> <MetaInfo text="optional" />
39+
- `WRANGLER_SEND_METRICS` <Type text="string" /> <MetaInfo text="optional" />
40+
- 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).
5141

52-
* 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.
42+
- `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`<Type text="string" /> <MetaInfo text="optional" />
43+
- 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.
5344

54-
* `CLOUDFLARE_API_BASE_URL` <Type text="string" /> <MetaInfo text="optional" />
45+
- `CLOUDFLARE_API_BASE_URL` <Type text="string" /> <MetaInfo text="optional" />
46+
- The default value is `"https://api.cloudflare.com/client/v4"`.
5547

56-
* The default value is `"https://api.cloudflare.com/client/v4"`.
48+
- `WRANGLER_LOG` <Type text="string" /> <MetaInfo text="optional" />
49+
- 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.
5750

58-
* `WRANGLER_LOG` <Type text="string" /> <MetaInfo text="optional" />
51+
- `WRANGLER_LOG_PATH` <Type text="string" /> <MetaInfo text="optional" />
52+
- 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.
5953

60-
* 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.
61-
62-
* `WRANGLER_LOG_PATH` <Type text="string" /> <MetaInfo text="optional" />
63-
64-
* 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.
65-
66-
* `FORCE_COLOR` <Type text="string" /> <MetaInfo text="optional" />
67-
68-
* 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`.
69-
70-
* `WRANGLER_DOCKER_HOST` <Type text="string" /> <MetaInfo text="optional" />
71-
72-
* 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.
54+
- `FORCE_COLOR` <Type text="string" /> <MetaInfo text="optional" />
55+
- 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`.
7456

7557
* `WRANGLER_HTTPS_KEY_PATH` <Type text="string" /> <MetaInfo text="optional" />
76-
77-
* Path to a custom HTTPS certificate key when running `wrangler dev`, to be used with `WRANGLER_HTTPS_CERT_PATH`.
58+
- Path to a custom HTTPS certificate key when running `wrangler dev`, to be used with `WRANGLER_HTTPS_CERT_PATH`.
7859

7960
* `WRANGLER_HTTPS_CERT_PATH` <Type text="string" /> <MetaInfo text="optional" />
61+
- Path to a custom HTTPS certificate when running `wrangler dev`, to be used with `WRANGLER_HTTPS_KEY_PATH`.
8062

81-
* Path to a custom HTTPS certificate when running `wrangler dev`, to be used with `WRANGLER_HTTPS_KEY_PATH`.
82-
83-
63+
- `DOCKER_HOST` <Type text="string" /> <MetaInfo text="optional" />
64+
- 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.
8465

8566
## Example `.env` file
8667

@@ -100,8 +81,8 @@ WRANGLER_LOG_PATH=../Desktop/my-logs/my-log-file.log
10081

10182
The following variables are deprecated. Use the new variables listed above to prevent any issues or unwanted messaging.
10283

103-
* `CF_ACCOUNT_ID`
104-
* `CF_API_TOKEN`
105-
* `CF_API_KEY`
106-
* `CF_EMAIL`
107-
* `CF_API_BASE_URL`
84+
- `CF_ACCOUNT_ID`
85+
- `CF_API_TOKEN`
86+
- `CF_API_KEY`
87+
- `CF_EMAIL`
88+
- `CF_API_BASE_URL`

0 commit comments

Comments
 (0)