Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion public/__redirects
Original file line number Diff line number Diff line change
Expand Up @@ -2421,4 +2421,9 @@
/ai-gateway/guardrails/* /ai-gateway/features/guardrails/:splat 301
/ai-gateway/websockets-api/* /ai-gateway/usage/websockets-api/:splat 301


# Containers
/containers/image-management /containers/platform-details/image-management 301
/containers/scaling-and-routing /containers/platform-details/scaling-and-routing 301
/containers/architecture /containers/platform-details/architecture 301
/containers/durable-object-methods /containers/platform-details/durable-object-methods 301
/containers/platform-details /containers/platform-details/architecture 301
66 changes: 0 additions & 66 deletions src/content/docs/containers/architecture.mdx

This file was deleted.

7 changes: 3 additions & 4 deletions src/content/docs/containers/beta-info.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pcx_content_type: reference
title: Beta Info & Roadmap
sidebar:
order: 2
order: 9
---

Currently, Containers are in beta. There are several changes we plan to make prior to GA:
Expand All @@ -24,7 +24,7 @@ by calling `get()` on their binding with a unique ID.
We plan to add official support for utilization-based autoscaling and latency-aware load balancing
in the future.

See the [Autoscaling documentation](/containers/scaling-and-routing) for more information.
See the [Autoscaling documentation](/containers/platform-details/scaling-and-routing) for more information.

### Reduction of log noise

Expand All @@ -38,7 +38,6 @@ We plan to automatically reduce log noise in the future.

The dashboard will be updated to show:

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

### Co-locating Durable Objects and Containers
Expand Down Expand Up @@ -71,6 +70,6 @@ There are several areas where we wish to gather feedback from users:
- Do you want to integrate Containers with any other Cloudflare services? If so, which ones and how?
- Do you want more ways to interact with a Container via Workers? If so, how?
- Do you need different mechanisms for routing requests to containers?
- Do you need different mechanisms for scaling containers? (see [scaling documentation](/containers/scaling-and-routing) for information on autoscaling plans)
- Do you need different mechanisms for scaling containers? (see [scaling documentation](/containers/platform-details/scaling-and-routing) for information on autoscaling plans)

At any point during the Beta, feel free to [give feedback using this form](https://forms.gle/CscdaEGuw5Hb6H2s7).
25 changes: 18 additions & 7 deletions src/content/docs/containers/container-package.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@
pcx_content_type: navigation
title: Container Package
sidebar:
order: 8
order: 5
---

import { PackageManagers } from "~/components";

When writing code that interacts with a container instance, you can either use a
Durable Object directly or use the [`Container` module](https://github.com/cloudflare/containers)
[Durable Object directly](/containers/platform-details/durable-object-methods) or use the [`Container` class](https://github.com/cloudflare/containers)
importable from [`@cloudflare/containers`](https://www.npmjs.com/package/@cloudflare/containers).

We recommend using the `Container` class for most use cases.

<PackageManagers pkg="@cloudflare/containers" />

Then, you can define a class that extends `Container`, and use it in your Worker:

```javascript
import { Container } from "@cloudflare/containers";

class MyContainer extends Container {
defaultPort = 8080;
sleepAfter = "5m";
}
```

We recommend using the `Container` class for most use cases.

Install it with `npm install @cloudflare/containers`.
export default {
async fetch(request, env) {
// gets default instance and forwards request from outside Worker
return env.MY_CONTAINER.getByName("hello").fetch(request);
},
};
```

The `Container` class extends `DurableObject` so all Durable Object functionality is available.
The `Container` class extends `DurableObject` so all [Durable Object](/durable-objects) functionality is available.
It also provides additional functionality and a nice interface for common container behaviors,
such as:

Expand Down
26 changes: 14 additions & 12 deletions src/content/docs/containers/examples/container-backend.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

summary: A simple frontend app with a containerized backend
pcx_content_type: example
title: Static Frontend, Container Backend
Expand Down Expand Up @@ -33,6 +32,7 @@ For a full example, see the [Static Frontend + Container Backend Template](https
{
"class_name": "Backend",
"image": "./Dockerfile",
"max_instances": 3
}
],
"durable_objects": {
Expand Down Expand Up @@ -166,7 +166,7 @@ select of of N instances of a Container to route requests to.
In the future, we will provide improved latency-aware load balancing and autoscaling.

This will make scaling stateless instances simple and routing more efficient. See the
[autoscaling documentation](/containers/scaling-and-routing) for more details.
[autoscaling documentation](/containers/platform-details/scaling-and-routing) for more details.
:::

## Define a backend container
Expand All @@ -176,6 +176,7 @@ Your container should be able to handle requests to `/api/widgets`.
In this case, we'll use a simple Golang backend that returns a hard-coded list of widgets.

<Details header="server.go">

```go
package main

Expand All @@ -186,22 +187,23 @@ import (
)

func handler(w http.ResponseWriter, r \*http.Request) {
widgets := []map[string]interface{}{
{"id": 1, "name": "Widget A"},
{"id": 2, "name": "Sprocket B"},
{"id": 3, "name": "Gear C"},
}
widgets := []map[string]interface{}{
{"id": 1, "name": "Widget A"},
{"id": 2, "name": "Sprocket B"},
{"id": 3, "name": "Gear C"},
}

w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
json.NewEncoder(w).Encode(widgets)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
json.NewEncoder(w).Encode(widgets)

}

func main() {
http.HandleFunc("/api/widgets", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
http.HandleFunc("/api/widgets", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}

```

</Details>
15 changes: 7 additions & 8 deletions src/content/docs/containers/examples/cron.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

summary: Running a container on a schedule using Cron Triggers
pcx_content_type: example
title: Cron Container
Expand Down Expand Up @@ -43,9 +42,7 @@ Use a cron expression in your Wrangler config to specify the schedule:
},
"migrations": [
{
"new_sqlite_classes": [
"CronContainer"
],
"new_sqlite_classes": ["CronContainer"],
"tag": "v1"
}
]
Expand All @@ -61,7 +58,6 @@ import { Container, getContainer } from "@cloudflare/containers";

export class CronContainer extends Container {
sleepAfter = "5m";
manualStart = true;
}

export default {
Expand All @@ -71,13 +67,16 @@ export default {
);
},

// scheduled is called when a cron trigger fires
async scheduled(
_controller: any,
env: { CRON_CONTAINER: DurableObjectNamespace<CronContainer> },
) {
await getContainer(env.CRON_CONTAINER).startContainer({
envVars: {
MESSAGE: "Start Time: " + new Date().toISOString(),
await getContainer(env.CRON_CONTAINER).startAndWaitForPorts({
startOptions: {
envVars: {
MESSAGE: "Start Time: " + new Date().toISOString(),
},
},
});
},
Expand Down
Loading
Loading