Skip to content

Commit 75ac717

Browse files
committed
more details and fixups
1 parent 0ece25c commit 75ac717

File tree

8 files changed

+115
-28
lines changed

8 files changed

+115
-28
lines changed

public/__redirects

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,3 +2371,9 @@
23712371
/realtime/realtimekit/get-started /realtime/realtimekit/getting-started/ 302
23722372
/realtime/introduction /realtime/realtimekit/introduction 302
23732373
/realtime/concepts /realtime/realtimekit/concepts 302
2374+
2375+
# Containers
2376+
/containers/platform-details/#limits /containers/platform-details/limits 301
2377+
/containers/image-management /containers/platform-details/image-management 301
2378+
/containers/scaling-and-routing /containers/platform-details/scaling-and-routing 301
2379+
/containers/architecture /containers/platform-details/architecture 301

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ We plan to automatically reduce log noise in the future.
3838

3939
The dashboard will be updated to show:
4040

41-
- the status of Container rollouts
4241
- links from Workers to their associated Containers
4342

4443
### Co-locating Durable Objects and Containers

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ export default {
151151
},
152152
};
153153
```
154+
155+
## Build-time environment variables
156+
157+
Finally, you can also set build-time environment variables that are only available when building the container image via the `image_vars` field in the Wrangler configuration.

src/content/docs/containers/faq.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ on image size and code execution time, among other factors.
8585

8686
## How do I use an existing container image?
8787

88-
See [image management documentation](/containers/image-management/#using-existing-images) for details.
88+
See [image management documentation](/containers/platform-details/image-management/#using-existing-images) for details.
8989

9090
## Is disk persistent? What happens to my disk when my container sleeps?
9191

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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](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/).
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/). Other tools like [Colima](https://github.com/abiosoft/colima) may also work.
2121

2222
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".
@@ -29,9 +29,11 @@ the `docker info` command will hang or return an error including the message "Ca
2929

3030
Run the following command to create and deploy a new Worker with a container, from the starter template:
3131

32-
```sh
33-
npm create cloudflare@latest -- --template=cloudflare/templates/containers-template
34-
```
32+
<PackageManagers
33+
type="create"
34+
pkg="cloudflare@latest"
35+
args={"--template=cloudflare/templates/containers-template"}
36+
/>
3537

3638
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/):
3739

@@ -40,7 +42,7 @@ When you want to deploy a code change to either the Worker or Container code, yo
4042
When you run `wrangler deploy`, the following things happen:
4143

4244
- Wrangler builds your container image using Docker.
43-
- Wrangler pushes your image to a [Container Image Registry](/containers/image-management/) that is automatically
45+
- Wrangler pushes your image to a [Container Image Registry](/containers/platform-details/image-management/) that is automatically
4446
integrated with your Cloudflare account.
4547
- Wrangler deploys your Worker, and configures Cloudflare's network to be ready to spawn instances of your container
4648

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

6870
Now, open the URL for your Worker. It should look something like `https://hello-containers.YOUR_ACCOUNT_NAME.workers.dev`.
6971

70-
If you make requests to the paths `/container/1` or `/container/2`, these requests are routed to specific containers.
72+
If you make requests to the paths `/container/1` or `/container/2`, your Worker routes requests to specific containers.
7173
Each different path after "/container/" routes to a unique container.
7274

7375
If you make requests to `/lb`, you will load balanace requests to one of 3 containers chosen at random.

src/content/docs/containers/index.mdx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ With Containers you can run:
4545
- Applications and libraries that require a full filesystem, specific runtime, or Linux-like environment
4646
- Existing applications and tools that have been distributed as container images
4747

48-
Container instances are spun up on-demand and controlled by code you write in your [Worker](/workers). Instead of chaining together API calls or writing Kubernetes operators, you just write JavaScript:
48+
Container instances are spun up on-demand and controlled by code you write in your [Worker](/workers). Instead of chaining together API calls or writing Kubernetes operators, you just write JavaScript:
49+
4950
<Tabs>
5051
<TabItem label="Worker Code">
5152
```js
@@ -57,14 +58,14 @@ export class MyContainer extends Container {
5758
}
5859

5960
async fetch(request, env) {
60-
const { "session-id": sessionId } = await request.json();
61-
// Get the container instance for the given session ID
62-
const containerInstance = getContainer(env.MY_CONTAINER, sessionId)
63-
// Pass the request to the container instance on its default port
64-
return containerInstance.fetch(request);
61+
const { "session-id": sessionId } = await request.json();
62+
// Get the container instance for the given session ID
63+
const containerInstance = getContainer(env.MY_CONTAINER, sessionId)
64+
// Pass the request to the container instance on its default port
65+
return containerInstance.fetch(request);
6566
}
6667

67-
```
68+
````
6869
</TabItem>
6970
<TabItem label="Worker Config">
7071
<WranglerConfig>
@@ -77,7 +78,7 @@ async fetch(request, env) {
7778
{
7879
"class_name": "MyContainer",
7980
"image": "./Dockerfile",
80-
"instances": 5,
81+
"max_instances": 5,
8182
}
8283
],
8384
"durable_objects": {
@@ -97,14 +98,21 @@ async fetch(request, env) {
9798
}
9899
],
99100
}
100-
```
101+
````
101102
102103
</WranglerConfig>
103104
</TabItem>
104105
</Tabs>
105106
106-
107-
<LinkButton variant="primary" href="/containers/get-started/">Get started</LinkButton> <LinkButton variant="secondary" href="https://dash.cloudflare.com/?to=/:account/workers/containers">Containers dashboard</LinkButton>
107+
<LinkButton variant="primary" href="/containers/get-started/">
108+
Get started
109+
</LinkButton>
110+
<LinkButton
111+
variant="secondary"
112+
href="https://dash.cloudflare.com/?to=/:account/workers/containers"
113+
>
114+
Containers dashboard
115+
</LinkButton>
108116
109117
---
110118
@@ -146,7 +154,11 @@ regional placement, Workflow and Queue integrations, AI-generated code execution
146154
containers with Wrangler.
147155
</LinkTitleCard>
148156
149-
<LinkTitleCard title="Limits" href="/containers/platform-details/#limits" icon="seti:lock">
157+
<LinkTitleCard
158+
title="Limits"
159+
href="/containers/platform-details/#limits"
160+
icon="seti:lock"
161+
>
150162
Learn about what limits Containers have and how to work within them.
151163
</LinkTitleCard>
152164
@@ -160,4 +172,3 @@ regional placement, Workflow and Queue integrations, AI-generated code execution
160172
</LinkTitleCard>
161173
162174
</CardGrid>
163-

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

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ sidebar:
55
order: 1
66
---
77

8-
## How and where containers run
8+
## How Containers run
9+
10+
Each container instance runs inside its own VM, which provides strong
11+
isolation from other workloads running on Cloudflare's network. Containers
12+
should be built for the `linux/amd64` architecture, and should stay within
13+
[size limits](/containers/platform-details/limits). Logging, metrics collection, and
14+
networking are automatically set up on each container.
15+
16+
## Where Containers run
917

1018
After you deploy a Worker that uses a Container, your image is uploaded to
11-
[Cloudflare's Registry](/containers/image-management) and distributed globally to Cloudflare's Network.
19+
[Cloudflare's Registry](/containers/platform-details/image-management) and distributed globally to Cloudflare's Network.
1220
Cloudflare will pre-schedule instances and pre-fetch images across the globe to ensure quick start
1321
times when scaling up the number of concurrent container instances. This allows you to call
1422
`env.YOUR_CONTAINER.get(id)` and get a new instance quickly without worrying
@@ -26,11 +34,29 @@ locations, some container instances may be started in locations that are farther
2634
the end-user. This is done to ensure that the container instance starts quickly. You are
2735
only charged for actively running instances and not for any unused pre-warmed images.
2836

29-
Each container instance runs inside its own VM, which provides strong
30-
isolation from other workloads running on Cloudflare's network. Containers
31-
should be built for the `linux/amd64` architecture, and should stay within
32-
[size limits](/containers/platform-details/#limits). Logging, metrics collection, and
33-
networking are automatically set up on each container.
37+
Once a particular container instance is running however (instances are defined with `MY_CONTAINER.get("unique-session-id")` ),
38+
any future requests while the container is alive will be routed to the initial location. However, if the container instance restarts,
39+
future requests could be routed to a different location.
40+
41+
Note that Workers are not necessarily co-located with their associated Containers.
42+
43+
An Example:
44+
45+
- A user deploys a Container. Cloudflare automatically readies instances across its Network.
46+
- A request is made from a client in Bariloche, Argentia. It reaches the Worker in
47+
Cloudflare's location in Neuquen, Argentina.
48+
- This Worker request calls `MY_CONTAINER.get("session-1337")` which brings up a Durable
49+
Object, which then calls `this.ctx.container.start`.
50+
- This requests the nearest free Container instance.
51+
- Cloudflare recognizes that an instance is free in Buenos Aires, Argentina, and
52+
starts it there.
53+
- A different user needs to route to the same container. This user's request reaches
54+
the Worker running in Cloudflare's location in San Diego.
55+
- The Worker again calls `MY_CONTAINER.get("session-1337")`.
56+
- If the initial container instance is still running, the request is routed to the location
57+
in Buenos Aires. If the initial container has gone to sleep, Cloudflare will once
58+
again try to find the nearest "free" instance of the Container, likely
59+
one in North America, and start an instance there.
3460

3561
## Life of a Container Request
3662

@@ -62,3 +88,41 @@ which will allow container instances to always run in the same location as their
6288
Because all Container requests are passed through a Worker, end-users cannot make TCP or
6389
UDP requests to a Container instance. If you have a use case that requires inbound TCP
6490
or UDP from an end-user, please [let us know](https://forms.gle/AGSq54VvUje6kmKu8).
91+
92+
### Cold starts
93+
94+
A cold start is when a container instance is started from a completely stopped state.
95+
96+
If you call `env.MY_CONTAINER.get(id)` with a completely novel ID and launch
97+
this instance for the first time, it will result in a cold start.
98+
99+
This will start the container image from its entrypoint for the first time. Depending
100+
on what this entrypoint does, it will take a variable amount of time to start.
101+
102+
Container cold starts can often be the 2-3 second range, but this is dependent
103+
on image size and code execution time, among other factors.
104+
105+
Cloudflare will automatically pre-fetch images and pre-warm instances across its network as you scale.
106+
However, because there are a finite number pre-warmed locations, some container instances may be started in
107+
locations that are farther away from the end-user. This is done to ensure that the container instance starts quickly.
108+
109+
You are only charged for actively running instances and not for any unused pre-warmed images.
110+
111+
### After a request
112+
113+
Cloudflare will not actively shut off a container instance after a specific amount of
114+
time. If you do not set `sleepAfter` on your Container class, or stop the instance
115+
manually, it will continue to run unless its host server is restarted. This
116+
happens on an irregular cadence, but frequently enough where Cloudflare does not
117+
guarantee that any instance will run for any set period of time.
118+
119+
When a container instance is going to be shut down, it is sent a `SIGTERM` signal,
120+
and then a `SIGKILL` signal after 15 minutes. You should perform any necessary
121+
cleanup to ensure a graceful shutdown in this time. The container instance
122+
will be rebooted elsewhere shortly after this.
123+
124+
All disk is ephemeral. When a Container instance goes to sleep, the next time
125+
it is started, it will have a fresh disk as defined by its container image.
126+
127+
Persistent disk is something the Cloudflare team is exploring in the future, but
128+
is not slated for the near term.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ class MyContainer extends Container {
3636
:::note
3737
If you supply environment variables with the same names, supplied values will override predefined values.
3838
:::
39+
More details about defining environment variables and secrets can be found in [this example](/containers/examples/env-vars-and-secrets).

0 commit comments

Comments
 (0)