[ PROMPT_NODE_24038 ]
Containers 配置说明
[ SKILL_DOCUMENTATION ]
## Wrangler 配置
### 基础容器配置
c
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2026-01-10",
"containers": [
{
"class_name": "MyContainer",
"image": "./Dockerfile", // Dockerfile 或包含 Dockerfile 的目录路径
"instance_type": "standard-1", // 预定义或自定义(见下文)
"max_instances": 10
}
],
"durable_objects": {
"bindings": [
{
"name": "MY_CONTAINER",
"class_name": "MyContainer"
}
]
},
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["MyContainer"] // 必须使用 new_sqlite_classes
}
]
}
关键配置要求:
- `image` - Dockerfile 或包含 Dockerfile 的目录路径
- `class_name` - 必须与导出的容器类名匹配
- `max_instances` - 最大并发容器实例数
- 必须配置 Durable Objects 绑定和迁移
### 实例类型
#### 预定义类型
| 类型 | vCPU | 内存 | 磁盘 |
|------|------|--------|------|
| lite | 1/16 | 256 MiB | 2 GB |
| basic | 1/4 | 1 GiB | 4 GB |
| standard-1 | 1/2 | 4 GiB | 8 GB |
| standard-2 | 1 | 6 GiB | 12 GB |
| standard-3 | 2 | 8 GiB | 16 GB |
| standard-4 | 4 | 12 GiB | 20 GB |
c
{
"containers": [
{
"class_name": "MyContainer",
"image": "./Dockerfile",
"instance_type": "standard-2" // 使用预定义类型
}
]
}
#### 自定义类型(2026 年 1 月功能)
c
{
"containers": [
{
"class_name": "MyContainer",
"image": "./Dockerfile",
"instance_type_custom": {
"vcpu": 2, // 1-4 vCPU
"memory_mib": 8192, // 512-12288 MiB (最高 12 GiB)
"disk_mib": 16384 // 2048-20480 MiB (最高 20 GB)
}
}
]
}
**自定义类型约束:**
- 每个 vCPU 最少 3 GiB 内存
- 每 1 GiB 内存最多 2 GB 磁盘
- 每个容器最多 4 vCPU、12 GiB 内存、20 GB 磁盘
### 账户限制
| 资源 | 限制 | 备注 |
|----------|-------|-------|
| 总内存(所有容器) | 400 GiB | 跨所有运行中的容器 |
| 总 vCPU(所有容器) | 100 | 跨所有运行中的容器 |
| 总磁盘(所有容器) | 2 TB | 跨所有运行中的容器 |
| 每个账户的镜像存储 | 50 GB | 存储的容器镜像 |
### 容器类属性
typescript
import { Container } from "@cloudflare/containers";
export class MyContainer extends Container {
// 端口配置
defaultPort = 8080;