Skip to content

Commit cc1ddf8

Browse files
authored
[Containers] Fix code snippets on landing page (#25220)
1 parent 3e6d35b commit cc1ddf8

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

src/content/docs/containers/index.mdx

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,65 +46,63 @@ With Containers you can run:
4646
- Existing applications and tools that have been distributed as container images
4747

4848
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">
51-
```js
52-
import { Container, getContainer } from "@cloudflare/containers";
53-
54-
export class MyContainer extends Container {
55-
defaultPort = 4000; // Port the container is listening on
56-
sleepAfter = "10m"; // Stop the instance if requests not sent for 10 minutes
57-
}
58-
59-
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);
65-
}
66-
67-
```
68-
</TabItem>
69-
<TabItem label="Worker Config">
70-
<WranglerConfig>
71-
72-
```json
73-
{
74-
"name": "container-starter",
75-
"main": "src/index.js",
76-
"containers": [
77-
{
78-
"class_name": "MyContainer",
79-
"image": "./Dockerfile",
80-
"instances": 5,
81-
}
82-
],
83-
"durable_objects": {
84-
"bindings": [
85-
{
86-
"class_name": "MyContainer",
87-
"name": "MY_CONTAINER"
88-
}
89-
]
90-
},
91-
"migrations": [
92-
{
93-
"new_sqlite_classes": [
94-
"MyContainer"
95-
],
96-
"tag": "v1"
52+
```js
53+
import { Container, getContainer } from "@cloudflare/containers";
54+
55+
export class MyContainer extends Container {
56+
defaultPort = 4000; // Port the container is listening on
57+
sleepAfter = "10m"; // Stop the instance if requests not sent for 10 minutes
9758
}
98-
],
99-
}
100-
```
10159

102-
</WranglerConfig>
103-
</TabItem>
60+
export default {
61+
async fetch(request, env) {
62+
const { "session-id": sessionId } = await request.json();
63+
// Get the container instance for the given session ID
64+
const containerInstance = getContainer(env.MY_CONTAINER, sessionId);
65+
// Pass the request to the container instance on its default port
66+
return containerInstance.fetch(request);
67+
},
68+
};
69+
```
70+
</TabItem>
71+
<TabItem label="Worker Config">
72+
<WranglerConfig>
73+
```json
74+
{
75+
"name": "container-starter",
76+
"main": "src/index.js",
77+
"compatibility_date": "$today",
78+
"containers": [
79+
{
80+
"class_name": "MyContainer",
81+
"image": "./Dockerfile",
82+
"max_instances": 5
83+
}
84+
],
85+
"durable_objects": {
86+
"bindings": [
87+
{
88+
"class_name": "MyContainer",
89+
"name": "MY_CONTAINER"
90+
}
91+
]
92+
},
93+
"migrations": [
94+
{
95+
"new_sqlite_classes": ["MyContainer"],
96+
"tag": "v1"
97+
}
98+
]
99+
}
100+
```
101+
</WranglerConfig>
102+
</TabItem>
104103
</Tabs>
105104

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>
105+
<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>
108106

109107
---
110108

0 commit comments

Comments
 (0)