Skip to content

Commit 8f96822

Browse files
authored
Apply suggestions from code review
1 parent 55e4850 commit 8f96822

File tree

4 files changed

+49
-55
lines changed

4 files changed

+49
-55
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ hideChildren: false
44
pcx_content_type: navigation
55
title: Examples
66
sidebar:
7-
order: 10
7+
order: 3
88
---
99

1010
import { GlossaryTooltip, ListExamples } from "~/components";

src/content/docs/containers/get-started.mdx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,47 @@ This example Worker should give you a sense for simple Container use, and provid
1717
### Ensure Docker is running locally
1818

1919
In this guide, we will build and push a container image alongside your Worker code. By default, this process uses
20-
Docker to do so. You must have Docker running locally when you run `wrangler deploy`.
20+
[Docker](https://www.docker.com/) to do so. You must have Docker running locally when you run `wrangler deploy`. For most people, the best way to install Docker is to follow the [docs for installing Docker Desktop](https://docs.docker.com/desktop/).
2121

22-
If Docker is running properly, the `docker info` command will successfully run. If Docker is not running,
22+
You can check that Docker is running properly by running the `docker info` command in your terminal. If Docker is running, the command will succeed. If Docker is not running,
2323
the `docker info` command will hang or return an error including the message "Cannot connect to the Docker daemon".
2424

2525
{/* FUTURE CHANGE: Add some image you can use if you don't have Docker running. */}
2626
{/* FUTURE CHANGE: Link to docs on alternative build/push options */}
2727

28-
## Deploy a Container to Workers
28+
## Deploy your first Container
2929

30-
Now that your environment is set up, you can write your Worker.
3130

32-
### Deploy from the Hello World Template
3331

34-
Use [C3](/learning-paths/workers/get-started/c3-and-wrangler/#c3) to create and deploy a new Worker using the "Hello World Containers" template.
32+
Run the following command to create and deploy a new Worker with a container, from the starter template:
3533

3634
```sh
3735
npm create cloudflare@latest -- --template=cloudflare/templates/hello-world-containers
3836
```
3937

40-
Subsequent updates to the Worker or Container code can be deployed using Wrangler:
38+
When you want to deploy a code change to either the Worker or Container code, you can run the following command using [Wrangler CLI](/workers/wrangler/:
4139

4240
<PackageManagers type="exec" pkg="wrangler" args="deploy" />
4341

44-
When you run this command, several things happen:
42+
When you run `wrangler deploy`, the following things happen:
4543

46-
- Wrangler builds your image using Docker.
47-
- Wrangler pushes your image to the Cloudchamber Image Registry, which is automatically
44+
- Wrangler builds your container image using Docker.
45+
- Wrangler pushes your image to a [Container Image Registry](/containers/image-management/) that is automatically
4846
integrated with your Cloudflare account.
49-
- Wrangler deploys your Worker, which includes setting up a "Container" for it to interact with.
47+
- Wrangler deploys your Worker, and configures Cloudflare's network to be ready to spawn instances of your container
5048

5149
:::note
52-
The build and push usually take the longest on the first deploy. Future deploys
53-
will go faster by [reusing cached image layers](https://docs.docker.com/build/cache/).
50+
The build and push usually take the longest on the first deploy. Subsequent deploys
51+
are faster, because they [reuse cached image layers](https://docs.docker.com/build/cache/).
5452
:::
5553

5654
After you deploy your Worker for the first time, you will need to wait several minutes until
5755
it is ready to receive requests. Unlike Workers, Containers take a few minutes to be provisioned.
5856
During this time, requests are sent to the Worker, but calls to the Container will error.
5957

60-
### Check deploy status
58+
### Check deployment status
6159

62-
After deploying, you can list containers in your accout with the following command:
60+
After deploying, run the following command to show a list of containers containers in your Cloudflare account, and their deployment status:
6361

6462
<PackageManagers type="exec" pkg="wrangler" args="containers list" />
6563

@@ -69,7 +67,7 @@ And see images deployed to the Cloudflare Registry with the following command:
6967

7068
### Make requests to Containers
7169

72-
Now, open the URL for your worker. It should look something like `https://hello-containers.YOUR_ACCOUNT_NAME.workers.dev`.
70+
Now, open the URL for your Worker. It should look something like `https://hello-containers.YOUR_ACCOUNT_NAME.workers.dev`.
7371

7472
If you make requests to the paths `/container/1` or `/container/2`, these requests are routed to specific containers.
7573
Each different path after "/container/" routes to a unique container.
@@ -78,17 +76,20 @@ If you make requests to `/lb`, you will load balanace requests to one of 3 conta
7876

7977
You can confirm this behavior by reading the output of each request.
8078

81-
## Understanding Durable Objects and Containers
79+
## Understanding the Code
80+
81+
Now that you've deployed your first container, let's explain what is happening in your Worker's code, in your configuration file, in your container's code, and how requests are routed.
82+
## Each Container is backed by its own Durable Object
8283

83-
Requests are initially handled by the Worker, then passed to container-enabled [Durable Objects](/durable-objects)
84-
that is defined by the [`Container` class](https://github.com/cloudflare/containers).
84+
Incoming requests are initially handled by the Worker, then passed to a container-enabled [Durable Object](/durable-objects).
85+
To simplify and reduce boilerplate code, Cloudflare provides a [`Container` class](https://github.com/cloudflare/containers) as part of the `@cloudflare/containers` NPM package.
8586

8687
You don't have to be familiar with Durable Objects to use Containers, but it may be helpful
8788
to understand how the basics.
8889

8990
Each Durable Object runs alongside an individual container instance, manages starting and stopping it, and
9091
can interact with the container through its ports. Containers will likely run near the Worker instance
91-
requesting them, but not necessarily. See ["How Locations are Selected"](/containers/platform-details/#how-are-locations-are-selected)
92+
requesting them, but not necessarily. Refer to ["How Locations are Selected"](/containers/platform-details/#how-are-locations-are-selected)
9293
for details.
9394

9495
In a simple app, the Durable Object may just boot the container and proxy requests to it.
@@ -100,11 +101,10 @@ on container status changes, and more.
100101
See the [documentation for Durable Object container methods](/durable-objects/api/container/) and the
101102
[`Container` class repository](https://github.com/cloudflare/containers) for more details.
102103

103-
## Understanding the Code
104104

105-
### Worker Config
105+
### Configuration
106106

107-
First, wrangler config sets up a container and a Durable Object that will run alongside it.
107+
Your [Wrangler configuration file](/workers/wrangler/configuration/) defines the configuration for both your Worker and your container:
108108

109109
<WranglerConfig>
110110

@@ -129,16 +129,16 @@ new_sqlite_classes = ["MyContainer"]
129129
Important points about this config:
130130

131131
- `image` points to a Dockerfile or to a directory containing a Dockerfile.
132-
- `class_name` must be a Durable Object class name.
132+
- `class_name` must be a [Durable Object class name](/durable-objects/api/base/).
133133
- `max_instances` declares the maximum number of simultaneously running container instances
134134
that will run.
135-
- The Durable Object must use `new_sqlite_classes` not `new_classes`.
135+
- The Durable Object must use [`new_sqlite_classes`](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) not `new_classes`.
136136

137137
### The Container Image
138138

139-
The container image itself has to run on the `linux/amd64` architecture, but aside from that has few limitations.
139+
Your container image must be able to run on the `linux/amd64` architecture, but aside from that, has few limitations.
140140

141-
In this case, it is a simple Golang server that responds to requests on port 8080 using
141+
In the example you just deployed, it is a simple Golang server that responds to requests on port 8080 using
142142
the `MESSAGE` environment variable that will be set in the Worker and an [auto-generated
143143
environment variable](/containers/platform-details/#environment-variables) `CLOUDFLARE_DEPLOYMENT_ID.`
144144

@@ -152,7 +152,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
152152
```
153153

154154
:::note
155-
After deploying the example code, feel free to replace the provided image with one of your own.
155+
After deploying the example code, to deploy a different image, you can replace the provided image with one of your own.
156156
:::
157157

158158
### Worker code
@@ -195,7 +195,7 @@ See the [Container class documentation](/containers/container-package) for more
195195

196196
#### Routing to Containers
197197

198-
In the Worker's main `fetch` handler, Containers are launched in one of two ways:
198+
When a request enters Cloudflare, your Worker's [`fetch` handler](/workers/runtime-apis/handlers/fetch/) is invoked. This is the code that handles the incoming request. The fetch handler in the example code, launches containers in two ways, on different routes:
199199

200200
- Making requests to `/container/` passes requests to a new container for
201201
each path. This is done by spinning up a new Container instance. You may note
@@ -211,8 +211,8 @@ In the Worker's main `fetch` handler, Containers are launched in one of two ways
211211
```
212212

213213
- Making requests to `/lb` will load balance requests across several containers.
214-
This uses a simple `getRandom` helper method currently, which picks an ID at random
215-
from a set number (in this case 3), then routes to that Container instance.
214+
This uses a simple `getRandom` helper method, which picks an ID at random
215+
from a set number (in this case 3), then routes to that Container instance. You can replace this with any routing or load balancing logic you choose to implement:
216216

217217
```js
218218
if (pathname.startsWith("/lb")) {
@@ -236,9 +236,7 @@ This allows for multiple ways of using Containers:
236236
Currently, routing requests to one of many interchangeable Container instances is accomplished
237237
with the `getRandom` helper.
238238

239-
This is a temporary solution until first-party support for utilization-aware autoscaling
240-
and latency-aware load balancing is added to Cloudflare Containers. We plan to add this
241-
in the coming months.
239+
This is temporary — we plan to add native support for latency-aware autoscaling and load balancing in the coming months.
242240
:::
243241

244242
## View Containers in your Dashboard

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
pcx_content_type: reference
3-
title: Local Dev
3+
title: Local Development
44
sidebar:
55
order: 3
66
---
77

8-
## Local Development
8+
You can run both your container and your Worker locally, without additional configuration, by running [`npx wrangler dev`](/workers/wrangler/commands/#dev) 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 is installed. For instance, you can use [Docker Desktop](https://docs.docker.com/desktop/)
@@ -26,22 +26,21 @@ local images are not removed, so that they can be reused in subsequent calls to
2626
`wrangler dev` or `wrangler deploy`.
2727

2828
:::note
29-
If your Worker app creates many container instances, you may hit local limits
30-
on concurrent containers.
29+
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.
3130

3231
Additionally, if you regularly rebuild containers locally, you may want to clear
3332
out old container images (using `docker image prune` or similar) to reduce disk used.
3433
:::
3534

3635
## Iterating on Container code
3736

38-
When using `wrangler dev`, standard Worker code is automatically reloaded by wrangler you save a change,
37+
When you use `wrangler dev`, your Worker's code is automatically reloaded by Wrangler each time you save a change,
3938
but code running within the container is not.
4039

41-
If you wish to rebuild your container with new code changes, you can hit the `[r]` key on your keyboard, and a
42-
rebuild will be triggered. Instances will be restarted with the new images.
40+
To rebuild your container with new code changes, you can hit the `[r]` key on your keyboard, which
41+
triggers a rebuild. Container instances will then be restarted with the newly built images.
4342

44-
You may prefer to set up your code watchers and reloading mechanisms, or mount a local directory
43+
You may prefer to set up your own code watchers and reloading mechanisms, or mount a local directory
4544
into the local container images to sync code changes. This can be done, but there is no built-in
4645
mechanism for doing so in Wrangler, and best-practices will depend on the languages and frameworks
4746
you are using in your container code.

src/content/docs/containers/platform-details.mdx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: navigation
3-
title: Platform Details
3+
title: Platform
44
sidebar:
55
order: 2
66
group:
@@ -9,39 +9,36 @@ sidebar:
99

1010
import { WranglerConfig } from "~/components";
1111

12-
This page containers general details about the Containers platform.
1312

1413
## Instance Types
1514

1615
The memory, vCPU, and disk space for Containers are set through predefined instance types.
17-
There are currently three instance types available for Containers users by default:
16+
Three instance types are currently available:
1817

1918
| Instance Type | Memory | vCPU | Disk |
2019
| ------------- | ------- | ---- | ---- |
2120
| dev | 256 MiB | 1/16 | 2 GB |
2221
| basic | 1 GiB | 1/4 | 4 GB |
2322
| standard | 4 GiB | 1/2 | 4 GB |
2423

25-
These are specified using the `instance_type` property in wrangler config.
24+
These are specified using the [`instance_type` property](/workers/wrangler/configuration/#containers) in your Worker's Wrangler configuration file. Looking for larger instances? [Give us feedback here](/containers/beta-info/#feedback-wanted) and tell us what size instances you need, and what you want to use them for.
2625

2726
## Limits
2827

29-
Containers limits are currently set per account. You may have higher
30-
limits on your account if configured as such.
3128

32-
The default limits during the initial beta phase are:
29+
While in open beta, the following limits are currently in effect:
3330

3431
| Feature | Workers Paid |
3532
| ------------------------------------------------- | ------------ |
36-
| GB Memory for concurrent live Container instances | 40GB [^1] |
37-
| vCPU for concurrent live Container instances | 20 [^1] |
38-
| GB Disk for concurrent live Container instances | 100GB [^1] |
33+
| GB Memory for all concurrent live Container instances | 40GB [^1] |
34+
| vCPU for all concurrent live Container instances | 20 [^1] |
35+
| GB Disk for all concurrent live Container instances | 100GB [^1] |
3936
| Image size | 2 GB |
40-
| Total image storage for account | 50 GB [^2] |
37+
| Total image storage per account | 50 GB [^2] |
4138

4239
[^1]: This limit will be raised as we continue the beta.
4340

44-
[^2]: Delete images with `wrangler containers delete` to free up space. Note that reverted Workers may then break.
41+
[^2]: Delete container images with `wrangler containers delete` to free up space. Note that if you delete a container image and then [roll back](/workers/configuration/versions-and-deployments/rollbacks/) your Worker to a previous version, this version may no longer work.
4542

4643
## Environment variables
4744

0 commit comments

Comments
 (0)