明末渊虚之羽:全部武器获取方法详解
2026-07-04 3381168
2026-07-04 0
flowchart LRA[本地构建镜像
sandbox-extra:0.1] --> B[打Registry标签
localhost:6000/...]B --> C[推送到本地Registry
docker push]C --> D[创建Snapshot
API / Dashboard]D --> E[Runner拉取镜像]E --> F[Snapshot状态: active]
| 参数 | 值 |
|---|---|
| Daytona API 地址 | http://localhost:3000 |
| Registry 地址(宿主机) | localhost:6000 |
| Registry 地址(容器内部) | registry:6000 ← 关键! |
| Registry 登录 | admin / password |
| Registry 项目 | daytona |
| 组织 ID (Organization ID) | 9038b0ab-b214-46d2-a14e-d2113ecf2fd4 |
| Dex OIDC 地址 | http://localhost:5556/dex |
| Web Dashboard | http://localhost:3000/dashboard |
Web 登录账号: [email protected] / passwordAPI Key:dtn_b4b9e38cfcc3677bae7d72dc0812ecf7dacdb5534789e9ce2d1b89bf605d1132
Daytona 使用 Dex 做 OIDC 认证,可以通过 Device Code Flow 或 Web 登录 获取 JWT Token。

方法 A:通过 Web 登录获取(最简单)
http://localhost:3000/dashboard[email protected] / password 登录Authorization: Bearer xxx方法 B:通过 Device Code Flow(命令行)
# 1. 获取设备认证码curl -s -X POST http://localhost:5556/dex/device/code -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=daytona&scope=openid%20profile%20email"# 返回示例:# { "device_code": "xxx", "user_code": "XXXX-XXXX",# "verification_uri_complete": "http://localhost:5556/dex/device?user_code=XXXX-XXXX" }# 2. 浏览器打开 verification_uri_complete 链接,用 [email protected] 登录# 3. 轮询获取 tokencurl -s -X POST http://localhost:5556/dex/token -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=urn:ietf:params:oauth:grant-type:device_code" -d "device_code=xxx" -d "client_id=daytona"
# 验证 JWT Token 有效,获取组织 IDcurl -s http://localhost:3000/api/organizations -H "Authorization: Bearer
# 1. 给镜像打上 Registry 标签docker tag sandbox-extra:0.1 localhost:6000/daytona/sandbox-extra:0.1# 2. 推送到本地 Registrydocker push localhost:6000/daytona/sandbox-extra:0.1
TOKEN="
参数说明:
| 参数 | 说明 | 建议值 |
|---|---|---|
name | Snapshot 名称,唯一标识 | sandbox-extra |
imageName | 容器内部 Registry 地址 | registry:6000/daytona/sandbox-extra:0.1 |
cpu | Sandbox 分配的 CPU 核数 | 2 |
memory | 内存大小 (GB) | 4 |
disk | 磁盘大小 (GB) | 10 |
sandboxClass | Sandbox 类型 | container |
curl -s http://localhost:3000/api/snapshots -H "Authorization: Bearer $TOKEN" -H "X-Daytona-Organization-ID: $ORG_ID" | jq '.items[] | {name, state, size, errorReason}'
可能的状态流转:
pending → pulling → active ✅ (成功)pending → pulling → error ❌ (失败,查看 errorReason)
SNAPSHOT_ID="
http://localhost:3000/dashboard[email protected] / password 登录无论哪种方式,都需要先将镜像推送到本地 Registry:
docker tag sandbox-extra:0.1 localhost:6000/daytona/sandbox-extra:0.1docker push localhost:6000/daytona/sandbox-extra:0.1
sandbox-extraregistry:6000/daytona/sandbox-extra:0.1registry:6000,不能用 localhost:6000pending → pulling → active另外,可以通过 Registry UI 查看已推送的镜像:
http://localhost:5100daytona/sandbox-extra 仓库及其标签Daytona CLI (daytona) 当前版本 (v0.190.0) 主要用于服务端管理和 Sandbox 交互,暂未提供直接的 snapshot 管理命令。
# 查看 CLI 当前可用的命令daytona --help
如果需要从 CLI 操作,可考虑使用 curl 封装脚本(见方式一)。
❌ 错误做法:
# 创建 snapshot 时使用了宿主机视角的地址"imageName": "localhost:6000/daytona/sandbox-extra:0.1"
❌ 报错信息:
Snapshot localhost:6000/daytona/sandbox-extra:0.1 failed to inspect in registry.Error: Error response from daemon: Get "http://localhost:6000/v2/":dial tcp [::1]:6000: connect: connection refused
✅ 正确做法:
# 使用 Docker 内部网络的服务名"imageName": "registry:6000/daytona/sandbox-extra:0.1"
原因分析:
宿主机视角:localhost:6000→可访问 RegistryRunner容器视角:localhost:6000→指向 Runner 自己 (连接被拒绝)Runner容器视角:registry:6000→Docker DNS 解析到 Registry 容器 (✅)
Runner 会去拉取镜像,所以要用 容器内部网络 的地址。
❌ 错误做法:
# 直接用 API Key 调用 POST /api/snapshotsAuthorization: Bearer dtn_b4b9e38cfcc3677bae7d72dc0812ecf7dacdb5534789e9ce2d1b89bf605d1132
❌ 报错信息:
403 Forbidden: Access denied
原因: 创建 snapshot 需要 write:snapshots 权限,而 API Key 默认可能没有此权限。
✅ 解决方法: 使用 JWT Token(通过 Web 登录获取)代替 API Key。
❌ 错误做法:
curl -X POST http://localhost:5556/dex/token -d "[email protected]&password=password"
❌ 报错信息:
{ "error": "unsupported_grant_type" }
原因: Dex 配置中未启用 password grant type,只支持:
urn:ietf:params:oauth:grant-type:device_code(设备码)urn:ietf:params:oauth:grant-type:token-exchange(令牌交换)✅ 解决方法: 通过 Web 登录获取 JWT,或使用 Device Code Flow。
第一次失败后需要先删除再重新创建,否则创建会失败。
当构建了新的 sandbox-extra:0.2(或更新版本)时,按以下步骤操作:
# 在你的构建目录下cd /root/daytona-sandbox-extra./build.sh# 或其他构建命令
# 打标签docker tag sandbox-extra:0.2 localhost:6000/daytona/sandbox-extra:0.2# 推送到 Registrydocker push localhost:6000/daytona/sandbox-extra:0.2
http://localhost:3000/dashboardsandbox-extra-v2(或不同的名称)registry:6000/daytona/sandbox-extra:0.2activeJWT="<你的JWT Token>"ORG_ID="9038b0ab-b214-46d2-a14e-d2113ecf2fd4"curl -s -X POST http://localhost:3000/api/snapshots -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" -H "X-Daytona-Organization-ID: $ORG_ID" -d '{"name": "sandbox-extra-v2","imageName": "registry:6000/daytona/sandbox-extra:0.2","cpu": 2,"memory": 4,"disk": 10,"sandboxClass": "container"}' | jq .
# file: /root/daytona/docker/push-sandbox-extra.shset -eVERSION="${1:-0.1}"JWT="$JWT_TOKEN"# 先 export JWT_TOKEN=...ORG_ID="9038b0ab-b214-46d2-a14e-d2113ecf2fd4"echo "=== 1. 打标签 ==="docker tag sandbox-extra:${VERSION} localhost:6000/daytona/sandbox-extra:${VERSION}echo "=== 2. 推送镜像 ==="docker push localhost:6000/daytona/sandbox-extra:${VERSION}echo "=== 3. 创建 Snapshot ==="curl -s -X POST http://localhost:3000/api/snapshots -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" -H "X-Daytona-Organization-ID: $ORG_ID" -d "{"name": "sandbox-extra-v${VERSION}","imageName": "registry:6000/daytona/sandbox-extra:${VERSION}","cpu": 2,"memory": 4,"disk": 10,"sandboxClass": "container"}" | jq .echo "=== 4. 等待拉取完成 ==="sleep 5curl -s http://localhost:3000/api/snapshots -H "Authorization: Bearer $JWT" -H "X-Daytona-Organization-ID: $ORG_ID" | jq '.items[] | {name, state, size, errorReason}'
使用方法:
export JWT_TOKEN="eyJxxxxx"bash /root/daytona/docker/push-sandbox-extra.sh 0.2
Q: 创建 snapshot 后一直卡在 pending 状态?
A: 检查 runner 是否正常运行:docker ps | grep runner。runner 负责拉取镜像。
Q: 状态变为 error,错误信息包含 "connection refused"?
A: 镜像地址使用了 localhost:6000,应改为 registry:6000。详见 坑 1。
Q: API 返回 401 Unauthorized?
A: Token 可能已过期。JWT Token 有效期约 24 小时,过期后重新通过 Web 登录获取。
Q: API 返回 403 Forbidden?
A: 改用 JWT Token 而不是 API Key。详见 坑 2。
Q: 如何获取 Organization ID?
A: 调 GET /api/organizations 接口:
curl -s http://localhost:3000/api/organizations -H "Authorization: Bearer $JWT" | jq '.[0].id'
Q: Registry 里有哪些镜像?
A: 通过 Registry API 查看:
# 查看所有仓库curl -s http://localhost:6000/v2/_catalog | jq .# 查看特定仓库的标签curl -s http://localhost:6000/v2/daytona/sandbox-extra/tags/list | jq .
Q: 如何查看 Runner 的日志排查问题?
A: docker logs daytona-runner-1 --tail 50
最后更新: 2026-07-02 | Daytona v0.190.0 | Docker Compose 部署