|
| 1 | +--- |
| 2 | +title: Containers |
| 3 | +order: 0 |
| 4 | +type: overview |
| 5 | +pcx_content_type: overview |
| 6 | +sidebar: |
| 7 | + order: 1 |
| 8 | +head: |
| 9 | + - tag: title |
| 10 | + content: Overview |
| 11 | +--- |
| 12 | + |
| 13 | +import { |
| 14 | + CardGrid, |
| 15 | + Description, |
| 16 | + Feature, |
| 17 | + LinkTitleCard, |
| 18 | + Plan, |
| 19 | + RelatedProduct, |
| 20 | + TabItem, |
| 21 | + Tabs, |
| 22 | +} from "~/components"; |
| 23 | + |
| 24 | +<Description> |
| 25 | + |
| 26 | +Enhance your Workers with serverless containerized applications |
| 27 | + |
| 28 | +</Description> |
| 29 | + |
| 30 | +<Plan type="workers-paid" /> |
| 31 | + |
| 32 | +With Containers, you can build applications that integrate Workers with a serverless container runtime. |
| 33 | +Deploy your image to Region:Earth without worrying about managing infrastructure, just define your |
| 34 | +Worker and `wrangler deploy`. |
| 35 | + |
| 36 | +This lets you run: |
| 37 | + |
| 38 | +- Resouce-intensive applications that use more memory, CPU, or disk than Workers allow |
| 39 | +- Applications and libraries that require a specific runtime or Linux-like environment |
| 40 | +- Existing applications or tools that are distributed as images |
| 41 | + |
| 42 | +<Tabs> |
| 43 | + <TabItem label="Container Code"> |
| 44 | +```js |
| 45 | +// get a container-enabled durable object and call a method on in |
| 46 | +async fetch(request, env) { |
| 47 | + const { "session-id": sessionId } = await request.json(); |
| 48 | + const id = env.CODE_EXECUTOR.idFromName(sessionId); |
| 49 | + return env.CODE_EXECUTOR.get(id).fetch(request); |
| 50 | +} |
| 51 | + |
| 52 | +// define a durable object to run alongside your container |
| 53 | + |
| 54 | +export class CodeExecutor extends DurableObject { |
| 55 | + // boot the container with the DO |
| 56 | + constructor(ctx, env) { |
| 57 | + super(ctx, env); |
| 58 | + ctx.blockConcurrencyWhile( |
| 59 | + startAndWaitForPort(ctx.container, CONTAINER_PORT) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + // proxy requests to the container |
| 64 | + async fetch(request) { |
| 65 | + return await proxyFetch(this.ctx.container, request, CONTAINER_PORT); |
| 66 | + } |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +```` |
| 71 | + |
| 72 | +</TabItem> |
| 73 | +<TabItem label="Container Config"> |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "name": "my-container-worker", |
| 78 | + "main": "src/index.js", |
| 79 | + "compatibility_date": "2025-03-20", |
| 80 | + "containers": [ |
| 81 | + { |
| 82 | + "image": "./Dockerfile", |
| 83 | + "sleep_after": "30s", |
| 84 | + "instance_type": "basic", |
| 85 | + "binding": "CODE_EXECUTOR", |
| 86 | + "class_name": "CodeExecutor" |
| 87 | + } |
| 88 | + ] |
| 89 | +} |
| 90 | +```` |
| 91 | +
|
| 92 | + </TabItem> |
| 93 | +
|
| 94 | +</Tabs> |
| 95 | +
|
| 96 | +See the [getting started guide](/containers/get-started/guide/) to start building with Containers. |
| 97 | +
|
| 98 | +--- |
| 99 | +
|
| 100 | +## Next Steps |
| 101 | +
|
| 102 | +<Feature header="Deploy your first Container" href="/containers/get-started/" cta="Deploy a Container"> |
| 103 | +
|
| 104 | +Build and push an image, call the Container from your Worker, understand scaling and routing. |
| 105 | +
|
| 106 | +</Feature> |
| 107 | +
|
| 108 | +<Feature header="Container Examples" href="/containers/build/rules-of-workflows/" cta="See Examples"> |
| 109 | +
|
| 110 | +See examples of how to use a Container with a Worker, including statelss and stateful routing, |
| 111 | +regional placement, Workflow and Queue integrations, AI-generated code execution, and short-lived workloads. |
| 112 | +
|
| 113 | +</Feature> |
| 114 | +
|
| 115 | +--- |
| 116 | +
|
| 117 | +## More resources |
| 118 | +
|
| 119 | +<CardGrid> |
| 120 | +
|
| 121 | +<LinkTitleCard |
| 122 | + title="Pricing" |
| 123 | + href="/containers/platform/pricing/" |
| 124 | + icon="seti:shell" |
| 125 | +> |
| 126 | + Learn about Containers pricing and how to estimate your usage. |
| 127 | +</LinkTitleCard> |
| 128 | +
|
| 129 | +<LinkTitleCard |
| 130 | + title="Limits" |
| 131 | + href="/containers/platform/limits/" |
| 132 | + icon="document" |
| 133 | +> |
| 134 | + Learn about what limits Containers have and how to work within them. |
| 135 | +</LinkTitleCard> |
| 136 | +
|
| 137 | +{/* TODO: better icon/link */} |
| 138 | +
|
| 139 | +<LinkTitleCard |
| 140 | + title="Wrangler" |
| 141 | + href="/workers/wrangler/commands/#containers" |
| 142 | + icon="document" |
| 143 | +> |
| 144 | + Learn more about the commands to develop, build and push images, and deploy |
| 145 | + containers with Wrangler. |
| 146 | +</LinkTitleCard> |
| 147 | +
|
| 148 | +<LinkTitleCard |
| 149 | + title="Closed Beta Discord" |
| 150 | + href="https://discord.cloudflare.com" |
| 151 | + icon="discord" |
| 152 | +> |
| 153 | + Connect with other users in the closed beta on Discord. Ask questions, show |
| 154 | + what you are building, and discuss the platform with other developers. |
| 155 | +</LinkTitleCard> |
| 156 | +
|
| 157 | +</CardGrid> |
0 commit comments