Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/containers/README.md
1# Cloudflare Containers Skill Reference23**APPLIES TO: Cloudflare Containers ONLY - NOT general Cloudflare Workers**45Use when working with Cloudflare Containers: deploying containerized apps on Workers platform, configuring container-enabled Durable Objects, managing container lifecycle, or implementing stateful/stateless container patterns.67## Beta Status89⚠️ Containers is currently in **beta**. API may change without notice. No SLA guarantees. Custom instance types added Jan 2026.1011## Core Concepts1213**Container as Durable Object:** Each container is a Durable Object with persistent identity. Accessed via `getByName(id)` or `getRandom()`.1415**Image deployment:** Images pre-fetched globally. Deployments use rolling strategy (not instant like Workers).1617**Lifecycle:** cold start (2-3s) → running → `sleepAfter` timeout → stopped. No autoscaling - manual load balancing via `getRandom()`.1819**Persistent identity, ephemeral disk:** Container ID persists, but disk resets on stop. Use Durable Object storage for persistence.2021## Quick Start2223```typescript24import { Container } from "@cloudflare/containers";2526export class MyContainer extends Container {27defaultPort = 8080;28sleepAfter = "30m";29}3031export default {32async fetch(request: Request, env: Env) {33const container = env.MY_CONTAINER.getByName("instance-1");34await container.startAndWaitForPorts();35return container.fetch(request);36}37};38```3940## Reading Order4142| Task | Files |43|------|-------|44| Setup new container project | README → configuration.md |45| Implement container logic | README → api.md → patterns.md |46| Choose routing pattern | patterns.md (routing section) |47| Debug issues | gotchas.md |48| Production hardening | gotchas.md → patterns.md (lifecycle) |4950## Routing Decision Tree5152**How should requests reach containers?**5354- **Same user/session → same container:** Use `getByName(sessionId)` for session affinity55- **Stateless, spread load:** Use `getRandom()` for load balancing56- **Job per container:** Use `getByName(jobId)` + explicit lifecycle management57- **Single global instance:** Use `getByName("singleton")`5859## When to Use Containers vs Workers6061**Use Containers when:**62- Need stateful, long-lived processes (sessions, WebSockets, games)63- Running existing containerized apps (Node.js, Python, custom binaries)64- Need filesystem access or specific system dependencies65- Per-user/session isolation with dedicated compute6667**Use Workers when:**68- Stateless HTTP handlers69- Sub-millisecond cold starts required70- Auto-scaling to zero critical71- Simple request/response patterns7273## In This Reference7475- **[configuration.md](configuration.md)** - Wrangler config, instance types, Container class properties, environment variables, account limits76- **[api.md](api.md)** - Container class API, startup methods, communication (HTTP/TCP/WebSocket), routing helpers, lifecycle hooks, scheduling, state inspection77- **[patterns.md](patterns.md)** - Routing patterns (session affinity, load balancing, singleton), WebSocket forwarding, graceful shutdown, Workflow/Queue integration78- **[gotchas.md](gotchas.md)** - Critical gotchas (WebSocket, startup methods), common errors with solutions, specific limits, beta caveats7980## See Also8182- [Durable Objects](../durable-objects/) - Containers extend Durable Objects83- [Workflows](../workflows/) - Orchestrate container operations84- [Queues](../queues/) - Trigger containers from queue messages85- [Cloudflare Docs](https://developers.cloudflare.com/containers/)86