Skip to content

Commit 3a674df

Browse files
committed
A variety of tweaks to containers docs
1 parent 8f0f7c1 commit 3a674df

18 files changed

+320
-304
lines changed

src/content/docs/containers/architecture.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ sidebar:
55
order: 9
66
---
77

8-
### How and where containers run
8+
This page describes the architecture of Cloudflare Containers.
9+
10+
## How and where containers run
911

1012
After you deploy a Worker that uses a Container, your image is uploaded to
1113
[Cloudflare's Registry](/containers/image-management) and distributed globally to Cloudflare's Network.
@@ -32,7 +34,7 @@ should be built for the `linux/amd64` architecture, and should stay within
3234
[size limits](/containers/platform-details/#limits). Logging, metrics collection, and
3335
networking are automatically set up on each container.
3436

35-
### Life of a Container Request
37+
## Life of a Container Request
3638

3739
When a request is made to any Worker, including one with an associated Container, it is generally handled
3840
by a datacenter in a location with the best latency between itself and the requesting user.
@@ -60,6 +62,6 @@ which will allow container instances to always run in the same location as their
6062
:::
6163

6264
Because all Container requests are passed through a Worker, end-users cannot make TCP or
63-
UDP requests to a Container instance. Workers themselves cal make TCO and UDP requests to
65+
UDP requests to a Container instance. Workers themselves can make TCO and UDP requests to
6466
the Container using the [`connect()` API](/workers/runtime-apis/tcp-sockets/#connect). If you have a use
6567
case that requires inbound TCP or UDP from an end-user, please [let us know](https://forms.gle/AGSq54VvUje6kmKu8).

src/content/docs/containers/beta-info.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ There are several areas where we wish to gather feedback from users:
7171
- Do you want to integrate Containers with any other Cloudflare services? If so, which ones and how?
7272
- Do you want more ways to interact with a Container via Workers? If so, how?
7373
- Do you need different mechanisms for routing requests to containers?
74-
- Do you need different mechanisms for scaling containers? (see scaling documentation for information on autoscaling plans)
74+
- Do you need different mechanisms for scaling containers? (see [scaling documentation](/containers/scaling-and-routing) for information on autoscaling plans)
7575

7676
At any point during the Beta, feel free to [give feedback using this form](https://forms.gle/CscdaEGuw5Hb6H2s7).

src/content/docs/containers/examples/container-backend.mdx

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: A simple frontend app with a containerized backend
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Static Frontend, Container Backend
86
sidebar:
@@ -20,44 +18,44 @@ but you can select from one of many frontend frameworks. See our [Workers framew
2018

2119
For a full example, see the [Static Frontend + Container Backend Template](https://github.com/mikenomitch/static-frontend-container-backend).
2220

23-
### Configure Static Assets and a Container
21+
## Configure Static Assets and a Container
2422

2523
<WranglerConfig>
26-
```jsonc
24+
```json
2725
{
28-
"name": "cron-container",
29-
"main": "src/index.ts",
30-
"assets": {
26+
"name": "cron-container",
27+
"main": "src/index.ts",
28+
"assets": {
3129
"directory": "./dist",
3230
"binding": "ASSETS"
3331
},
34-
"containers": [
35-
{
36-
"class_name": "Backend",
37-
"image": "./Dockerfile",
38-
}
39-
],
40-
"durable_objects": {
41-
"bindings": [
42-
{
43-
"class_name": "Backend",
44-
"name": "BACKEND"
45-
}
46-
]
47-
},
48-
"migrations": [
49-
{
50-
"new_sqlite_classes": [
51-
"Backend"
52-
],
53-
"tag": "v1"
54-
}
55-
]
32+
"containers": [
33+
{
34+
"class_name": "Backend",
35+
"image": "./Dockerfile",
36+
}
37+
],
38+
"durable_objects": {
39+
"bindings": [
40+
{
41+
"class_name": "Backend",
42+
"name": "BACKEND"
43+
}
44+
]
45+
},
46+
"migrations": [
47+
{
48+
"new_sqlite_classes": [
49+
"Backend"
50+
],
51+
"tag": "v1"
52+
}
53+
]
5654
}
5755
```
5856
</WranglerConfig>
5957

60-
### Add a simple index.html file to serve
58+
## Add a simple index.html file to serve
6159

6260
Create a simple `index.html` file in the `./dist` directory.
6361

@@ -125,26 +123,21 @@ Create a simple `index.html` file in the `./dist` directory.
125123
```
126124
</Details>
127125

128-
In this example, we are using Alpine.js to fetch a list of widgets from "/api/widgets".
126+
In this example, we are using [Alpine.js](https://alpinejs.dev/) to fetch a list of widgets from "/api/widgets".
129127

130128
This is meant to be a very simple example, but you can get significantly more complex.
131129
See [examples of Workers integrating with frontend frameworks](/workers/framework-guides/web-apps/) for more information.
132130

133-
### Define a Worker
131+
## Define a Worker
134132

135133
Your Worker needs to be able to both serve static assets and route requests to the containerized backend.
136134

137135
In this case, we will pass requests to one of three container instances if the route starts with `/api`,
138136
and all other requests will be served as static assets.
139137

140-
```ts
138+
```javascript
141139
import { Container, getRandom } from "@cloudflare/containers";
142140

143-
export interface Env {
144-
BACKEND: DurableObjectNamespace<Backend>;
145-
ASSETS: Fetcher;
146-
}
147-
148141
const INSTANCE_COUNT = 3;
149142

150143
class Backend extends Container {
@@ -153,7 +146,7 @@ class Backend extends Container {
153146
}
154147

155148
export default {
156-
async fetch(request: Request, env: Env): Promise<Response> {
149+
async fetch(request, env) {
157150
const url = new URL(request.url);
158151
if (url.pathname.startsWith("/api")) {
159152
// note: "getRandom" to be replaced with latency-aware routing in the near future
@@ -176,7 +169,7 @@ This will make scaling stateless instances simple and routing more efficient. Se
176169
[autoscaling documentation](/containers/scaling-and-routing) for more details.
177170
:::
178171

179-
### Define a backend container
172+
## Define a backend container
180173

181174
Your container should be able to handle requests to `/api/widgets`.
182175

@@ -212,4 +205,3 @@ log.Fatal(http.ListenAndServe(":8080", nil))
212205

213206
```
214207
</Details>
215-
```

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: Running a container on a schedule using Cron Triggers
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Cron Container
86
sidebar:
@@ -20,35 +18,37 @@ Use a cron expression in your Wrangler config to specify the schedule:
2018

2119
<WranglerConfig>
2220

23-
```jsonc
21+
```json
2422
{
2523
"name": "cron-container",
2624
"main": "src/index.ts",
2725
"triggers": {
2826
"crons": [
29-
"*/2 * * * *", // Run every 2 minutes
30-
],
27+
"*/2 * * * *" // Run every 2 minutes
28+
]
3129
},
3230
"containers": [
3331
{
3432
"class_name": "CronContainer",
35-
"image": "./Dockerfile",
36-
},
33+
"image": "./Dockerfile"
34+
}
3735
],
3836
"durable_objects": {
3937
"bindings": [
4038
{
4139
"class_name": "CronContainer",
42-
"name": "CRON_CONTAINER",
43-
},
44-
],
40+
"name": "CRON_CONTAINER"
41+
}
42+
]
4543
},
4644
"migrations": [
4745
{
48-
"new_sqlite_classes": ["CronContainer"],
49-
"tag": "v1",
50-
},
51-
],
46+
"new_sqlite_classes": [
47+
"CronContainer"
48+
],
49+
"tag": "v1"
50+
}
51+
]
5252
}
5353
```
5454

src/content/docs/containers/examples/durable-object-interface.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: Various examples calling Containers directly from Durable Objects
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Using Durable Objects Directly
86
external_link: https://github.com/cloudflare/containers-demos

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
---
22
type: example
33
summary: Pass in environment variables and secrets to your container
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Env Vars and Secrets
86
sidebar:
97
order: 6
108
description: Pass in environment variables and secrets to your container
119
---
1210

13-
import { WranglerConfig } from "~/components";
11+
import { WranglerConfig, PackageManagers } from "~/components";
1412

1513
Environment variables can be passed into a Container using the `envVars` field
1614
in the `Container` class, or by setting manually when the Container starts.
@@ -29,45 +27,54 @@ be passing in:
2927
In practice, you may just use one of the methods for storing secrets, but
3028
we will show both for completeness.
3129

32-
### Creating secrets
30+
## Creating secrets
3331

3432
First, let's create the `"CONTAINER_SECRET_KEY"` secret in Worker Secrets:
3533

36-
```bash
37-
npx wrangler secret put CONTAINER_SECRET_KEY
38-
```
34+
<PackageManagers
35+
type="exec"
36+
pkg="wrangler"
37+
args="secret put CONTAINER_SECRET_KEY"
38+
/>
3939

4040
Then, let's create a store called "demo" in the Secret Store, and add
41-
he `"ACCOUNT_API"` secret to it:
41+
the `"ACCOUNT_API_KEY"` secret to it:
4242

43-
```bash
44-
wrangler secrets-store store create demo --remote
45-
wrangler secrets-store secret create demo --name ACCOUNT_API_KEY --scopes workers --remote
46-
```
43+
<PackageManagers
44+
type="exec"
45+
pkg="wrangler"
46+
args="secrets-store store create demo --remote"
47+
/>
48+
49+
<PackageManagers
50+
type="exec"
51+
pkg="wrangler"
52+
args="secrets-store secret create demo --name ACCOUNT_API_KEY --scopes workers --remote"
53+
/>
4754

4855
For full details on how to create secrets, see the [Workers Secrets documentation](/workers/configuration/secrets/)
4956
and the [Secret Store documentation](/secrets-store/integrations/workers/).
5057

51-
### Adding a secrets binding
58+
## Adding a secrets binding
5259

5360
Next, we need to add bindings to access our secrets and environment variables
5461
in Wrangler configuration.
5562

5663
<WranglerConfig>
5764

58-
```jsonc
65+
```json
5966
{
6067
"name": "my-container-worker",
6168
"vars": {
62-
"ACCOUNT_NAME": "my-account",
69+
"ACCOUNT_NAME": "my-account"
6370
},
6471
"secrets_store_secrets": [
6572
{
6673
"binding": "SECRET_STORE",
6774
"store_id": "demo",
68-
"secret_name": "ACCOUNT_API_KEY",
69-
},
70-
],
75+
"secret_name": "ACCOUNT_API_KEY"
76+
}
77+
]
7178
// rest of the configuration...
7279
}
7380
```
@@ -80,7 +87,7 @@ added to `env`.
8087
Also note that we did not configure anything specific for environment variables
8188
or secrets in the container-related portion of wrangler configuration.
8289

83-
### Using `envVars` on the Container class
90+
## Using `envVars` on the Container class
8491

8592
Now, let's define a Container using the `envVars` field in the `Container` class:
8693

@@ -93,15 +100,13 @@ export class MyContainer extends Container {
93100
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY,
94101
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY,
95102
};
96-
MESSAGE: 'I was passed in via the container class!',
97-
};
98103
}
99104
```
100105

101106
Every instance of this `Container` will now have these variables and secrets
102107
set as environment variables when it launches.
103108

104-
### Setting environment variables per-instance
109+
## Setting environment variables per-instance
105110

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import { GlossaryTooltip, ListExamples } from "~/components";
1111

1212
Explore the following examples of Container functionality:
1313

14-
<ListExamples directory="containers/examples/" />
14+
<ListExamples directory="containers/examples" />

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: Run multiple instances across Cloudflare's network
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Stateless Instances
86
sidebar:

src/content/docs/containers/examples/status-hooks.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: Execute Workers code in reaction to Container status changes
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Status Hooks
86
sidebar:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
type: example
33
summary: Forwarding a Websocket request to a Container
4-
tags:
5-
- Containers
64
pcx_content_type: example
75
title: Websocket to Container
86
sidebar:

0 commit comments

Comments
 (0)