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/get-started.mdx
+32-34Lines changed: 32 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,49 +17,47 @@ This example Worker should give you a sense for simple Container use, and provid
17
17
### Ensure Docker is running locally
18
18
19
19
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/).
21
21
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,
23
23
the `docker info` command will hang or return an error including the message "Cannot connect to the Docker daemon".
24
24
25
25
{/* FUTURE CHANGE: Add some image you can use if you don't have Docker running. */}
26
26
{/* FUTURE CHANGE: Link to docs on alternative build/push options */}
27
27
28
-
## Deploy a Container to Workers
28
+
## Deploy your first Container
29
29
30
-
Now that your environment is set up, you can write your Worker.
31
30
32
-
### Deploy from the Hello World Template
33
31
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:
Subsequent updates to the Worker or Container codecan 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/:
@@ -69,7 +67,7 @@ And see images deployed to the Cloudflare Registry with the following command:
69
67
70
68
### Make requests to Containers
71
69
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`.
73
71
74
72
If you make requests to the paths `/container/1` or `/container/2`, these requests are routed to specific containers.
75
73
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
78
76
79
77
You can confirm this behavior by reading the output of each request.
80
78
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
82
83
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.
85
86
86
87
You don't have to be familiar with Durable Objects to use Containers, but it may be helpful
87
88
to understand how the basics.
88
89
89
90
Each Durable Object runs alongside an individual container instance, manages starting and stopping it, and
90
91
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)
92
93
for details.
93
94
94
95
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.
100
101
See the [documentation for Durable Object container methods](/durable-objects/api/container/) and the
101
102
[`Container` class repository](https://github.com/cloudflare/containers) for more details.
102
103
103
-
## Understanding the Code
104
104
105
-
### Worker Config
105
+
### Configuration
106
106
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:
-`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/).
133
133
-`max_instances` declares the maximum number of simultaneously running container instances
134
134
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`.
136
136
137
137
### The Container Image
138
138
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.
140
140
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
142
142
the `MESSAGE` environment variable that will be set in the Worker and an [auto-generated
@@ -152,7 +152,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
152
152
```
153
153
154
154
:::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.
156
156
:::
157
157
158
158
### Worker code
@@ -195,7 +195,7 @@ See the [Container class documentation](/containers/container-package) for more
195
195
196
196
#### Routing to Containers
197
197
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:
199
199
200
200
- Making requests to `/container/` passes requests to a new container for
201
201
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
211
211
```
212
212
213
213
- 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:
216
216
217
217
```js
218
218
if (pathname.startsWith("/lb")) {
@@ -236,9 +236,7 @@ This allows for multiple ways of using Containers:
236
236
Currently, routing requests to one of many interchangeable Container instances is accomplished
237
237
with the `getRandom` helper.
238
238
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.
Copy file name to clipboardExpand all lines: src/content/docs/containers/local-dev.mdx
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
2
pcx_content_type: reference
3
-
title: Local Dev
3
+
title: Local Development
4
4
sidebar:
5
5
order: 3
6
6
---
7
7
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.
9
9
10
10
To develop Container-enabled Workers locally, you will need to first ensure that a
11
11
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
26
26
`wrangler dev` or `wrangler deploy`.
27
27
28
28
:::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.
31
30
32
31
Additionally, if you regularly rebuild containers locally, you may want to clear
33
32
out old container images (using `docker image prune` or similar) to reduce disk used.
34
33
:::
35
34
36
35
## Iterating on Container code
37
36
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,
39
38
but code running within the container is not.
40
39
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.
43
42
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
45
44
into the local container images to sync code changes. This can be done, but there is no built-in
46
45
mechanism for doing so in Wrangler, and best-practices will depend on the languages and frameworks
Copy file name to clipboardExpand all lines: src/content/docs/containers/platform-details.mdx
+9-12Lines changed: 9 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
pcx_content_type: navigation
3
-
title: Platform Details
3
+
title: Platform
4
4
sidebar:
5
5
order: 2
6
6
group:
@@ -9,39 +9,36 @@ sidebar:
9
9
10
10
import { WranglerConfig } from"~/components";
11
11
12
-
This page containers general details about the Containers platform.
13
12
14
13
## Instance Types
15
14
16
15
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:
18
17
19
18
| Instance Type | Memory | vCPU | Disk |
20
19
| ------------- | ------- | ---- | ---- |
21
20
| dev | 256 MiB | 1/16 | 2 GB |
22
21
| basic | 1 GiB | 1/4 | 4 GB |
23
22
| standard | 4 GiB | 1/2 | 4 GB |
24
23
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.
26
25
27
26
## Limits
28
27
29
-
Containers limits are currently set per account. You may have higher
30
-
limits on your account if configured as such.
31
28
32
-
The default limits during the initial beta phase are:
29
+
While in open beta, the following limits are currently in effect:
| 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]|
39
36
| Image size | 2 GB |
40
-
| Total image storage for account | 50 GB [^2]|
37
+
| Total image storage per account | 50 GB [^2]|
41
38
42
39
[^1]: This limit will be raised as we continue the beta.
43
40
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.
0 commit comments