Skip to content

Commit 6f715c5

Browse files
committed
Containers docs: Uses importable env and removes manualStart
1 parent c76c5bd commit 6f715c5

File tree

5 files changed

+29
-60
lines changed

5 files changed

+29
-60
lines changed

src/content/docs/containers/examples/cron.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { Container, getContainer } from "@cloudflare/containers";
6161

6262
export class CronContainer extends Container {
6363
sleepAfter = "5m";
64-
manualStart = true;
6564
}
6665

6766
export default {

src/content/docs/containers/examples/env-vars-and-secrets.mdx

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,22 @@ import { WranglerConfig, PackageManagers } from "~/components";
1313
Environment variables can be passed into a Container using the `envVars` field
1414
in the `Container` class, or by setting manually when the Container starts.
1515

16-
Secrets can be passed into a Container by using [Worker Secrets](/workers/configuration/secrets/)
17-
or the [Secret Store](/secrets-store/integrations/workers/), then passing them into the Container
18-
as environment variables.
16+
Secrets can be passed into a Container by using [Worker Secrets](/workers/configuration/secrets/),
17+
then passing them into the Container as environment variables.
1918

2019
These examples show the various ways to pass in secrets and environment variables. In each, we will
2120
be passing in:
2221

2322
- the variable `"ACCOUNT_NAME"` as a hard-coded environment variable
24-
- the secret `"CONTAINER_SECRET_KEY"` as a secret from Worker Secrets
25-
- the secret `"ACCOUNT_API_KEY"` as a secret from the Secret Store
26-
27-
In practice, you may just use one of the methods for storing secrets, but
28-
we will show both for completeness.
23+
- the secret `"ACCOUNT_API_KEY"` as a secret from Worker Secrets
2924

3025
## Creating secrets
3126

32-
First, let's create the `"CONTAINER_SECRET_KEY"` secret in Worker Secrets:
33-
34-
<PackageManagers
35-
type="exec"
36-
pkg="wrangler"
37-
args="secret put CONTAINER_SECRET_KEY"
38-
/>
39-
40-
Then, let's create a store called "demo" in the Secret Store, and add
41-
the `"ACCOUNT_API_KEY"` secret to it:
42-
43-
<PackageManagers
44-
type="exec"
45-
pkg="wrangler"
46-
args="secrets-store store create demo --remote"
47-
/>
27+
First, let's create the `"ACCOUNT_API_KEY"` secret in Worker Secrets:
4828

49-
<PackageManagers
50-
type="exec"
51-
pkg="wrangler"
52-
args="secrets-store secret create demo --name ACCOUNT_API_KEY --scopes workers --remote"
53-
/>
29+
<PackageManagers type="exec" pkg="wrangler" args="secret put ACCOUNT_API_KEY" />
5430

55-
For full details on how to create secrets, see the [Workers Secrets documentation](/workers/configuration/secrets/)
56-
and the [Secret Store documentation](/secrets-store/integrations/workers/).
31+
For full details on how to create secrets, see the [Workers Secrets documentation](/workers/configuration/secrets/).
5732

5833
## Adding a secrets binding
5934

@@ -66,15 +41,8 @@ in Wrangler configuration.
6641
{
6742
"name": "my-container-worker",
6843
"vars": {
69-
"ACCOUNT_NAME": "my-account"
70-
},
71-
"secrets_store_secrets": [
72-
{
73-
"binding": "SECRET_STORE",
74-
"store_id": "demo",
75-
"secret_name": "ACCOUNT_API_KEY"
76-
}
77-
]
44+
"ACCOUNT_API_KEY": "abcdef12345"
45+
}
7846
// rest of the configuration...
7947
}
8048
```
@@ -92,13 +60,14 @@ or secrets in the container-related portion of wrangler configuration.
9260
Now, let's define a Container using the `envVars` field in the `Container` class:
9361

9462
```js
63+
import { env } from "cloudflare:workers";
64+
9565
export class MyContainer extends Container {
96-
defaultPort = 8080;
97-
sleepAfter = '10s';
98-
envVars = {
99-
ACCOUNT_NAME: env.ACCOUNT_NAME,
100-
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY,
101-
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY,
66+
defaultPort = 8080;
67+
sleepAfter = "10s";
68+
envVars = {
69+
ACCOUNT_NAME: env.ACCOUNT_NAME,
70+
ACCOUNT_API_KEY: env.ACCOUNT_API_KEY,
10271
};
10372
}
10473
```
@@ -110,14 +79,13 @@ set as environment variables when it launches.
11079

11180
But what if you want to set environment variables on a per-instance basis?
11281

113-
In this case, set `manualStart` then use the `start` method to pass in environment variables for each instance.
82+
In this case, use the `start` method to pass in environment variables for each instance.
11483
We'll assume that we've set additional secrets in the Secret Store.
11584

11685
```js
11786
export class MyContainer extends Container {
11887
defaultPort = 8080;
11988
sleepAfter = '10s';
120-
manualStart = true;
12189
}
12290

12391
export default {
@@ -134,16 +102,14 @@ export default {
134102
await instanceOne.start({
135103
envVars: {
136104
ACCOUNT_NAME: env.ACCOUNT_NAME + "-1",
137-
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_ONE,
138-
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
105+
ACCOUNT_API_KEY: env.ACCOUNT_API_KEY_ONE,
139106
}
140107
)
141108

142109
await instanceTwo.start({
143110
envVars: {
144111
ACCOUNT_NAME: env.ACCOUNT_NAME + "-2",
145-
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_TWO,
146-
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
112+
ACCOUNT_API_KEY: env.ACCOUNT_API_KEY_TWO,
147113
}
148114
)
149115
return new Response('Container instances launched');

src/content/docs/containers/faq.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,24 @@ to define secrets for your Workers.
135135
Then you can pass these secrets to your Container using the `envVars` property:
136136

137137
```javascript
138+
import { env } from "cloudflare:workers";
139+
138140
class MyContainer extends Container {
139141
defaultPort = 5000;
140142
envVars = {
141-
MY_SECRET: this.env.MY_SECRET,
143+
MY_SECRET: env.MY_SECRET,
142144
};
143145
}
144146
```
145147

146148
Or when starting a Container instance on a Durable Object:
147149

148150
```javascript
151+
import { env } from "cloudflare:workers";
152+
149153
this.ctx.container.start({
150154
env: {
151-
MY_SECRET: this.env.MY_SECRET,
155+
MY_SECRET: env.MY_SECRET,
152156
},
153157
});
154158
```

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ the `image` attribute to a local path, the image will be built using the local D
1717
If the `image` attribute is set to a URL, the image will be pulled from the associated registry.
1818

1919
Container instances will be launched locally when your Worker code calls to create
20-
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+
a new container. This may happen when calling `.fetch()`, `.containerFetch()` or `start()`
21+
on a `Container` instance. Wrangler will boot new instances and automatically route
22+
requests to the correct local container.
2323

2424
When `wrangler dev` stops, all associated container instances are stopped, but
2525
local images are not removed, so that they can be reused in subsequent calls to

src/content/docs/containers/scaling-and-routing.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ sidebar:
88
### Scaling container instances with `get()`
99

1010
Currently, Containers are only scaled manually by calling `BINDING.get()` with a unique ID, then
11-
starting the container. Unless `manualStart` is set to `true` on the Container class, each
12-
instance will start when `get()` is called.
11+
starting the container. Each instance will start when the first request is made to it with `fetch()` or
12+
when manually started with `start()`.
1313

1414
```
1515
// gets 3 container instances

0 commit comments

Comments
 (0)