您的位置:首页 > 手游攻略 > 本地构建的自定义sandbox-extra镜像推送至沙盒daytona的snapshot列表中

本地构建的自定义sandbox-extra镜像推送至沙盒daytona的snapshot列表中

作者:互联网  时间: 2026-07-04 10:32:00  

Sandbox Extra 镜像推送与升级指南

目录

  1. 整体流程概览
  2. 前置准备与关键参数
  3. 方式一:通过 Daytona API 创建 Snapshot(推荐)
  4. 方式二:通过 Web Dashboard 操作
  5. 方式三:通过 Daytona CLI 操作(开发中)
  6. 踩坑记录
  7. 后续升级镜像的标准操作流程
  8. 常见问题 FAQ

1. 整体流程概览

flowchart LRA[本地构建镜像<br/>sandbox-extra:0.1] --> B[打Registry标签<br/>localhost:6000/...]B --> C[推送到本地Registry<br/>docker push]C --> D[创建Snapshot<br/>API / Dashboard]D --> E[Runner拉取镜像]E --> F[Snapshot状态: active]

2. 前置准备与关键参数

2.1 环境信息

参数
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 Dashboardhttp://localhost:3000/dashboard

2.2 认证凭据

Web 登录账号: [email protected] / passwordAPI Key:dtn_b4b9e38cfcc3677bae7d72dc0812ecf7dacdb5534789e9ce2d1b89bf605d1132

3. 方式一:通过 Daytona API 创建 Snapshot(推荐)

3.1 获取 JWT Token

Daytona 使用 Dex 做 OIDC 认证,可以通过 Device Code Flow 或 Web 登录 获取 JWT Token。

本地构建的自定义sandbox-extra镜像推送到沙盒daytona的snapshot列表中

方法 A:通过 Web 登录获取(最简单)

  1. 打开浏览器访问 http://localhost:3000/dashboard
  2. [email protected] / password 登录
  3. 登录后从浏览器开发者工具中复制 JWT Token:
    • F12 → Application → Local Storage → 找到 token
    • 或者在 API 请求头中复制 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"

3.2 验证 Token

# 验证 JWT Token 有效,获取组织 IDcurl -s http://localhost:3000/api/organizations -H "Authorization: Bearer <JWT_TOKEN>" | jq .# 返回示例:# [ { "id": "9038b0ab-b214-46d2-a14e-d2113ecf2fd4", "name": "Personal", ... } ]

3.3 推送镜像到本地 Registry

# 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

3.4 创建 Snapshot

TOKEN="<JWT_TOKEN>"ORG_ID="9038b0ab-b214-46d2-a14e-d2113ecf2fd4"curl -s -X POST http://localhost:3000/api/snapshots -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "X-Daytona-Organization-ID: $ORG_ID" -d '{"name": "sandbox-extra","imageName": "registry:6000/daytona/sandbox-extra:0.1","cpu": 2,"memory": 4,"disk": 10,"sandboxClass": "container"}' | jq .

参数说明:

参数说明建议值
nameSnapshot 名称,唯一标识sandbox-extra
imageName容器内部 Registry 地址registry:6000/daytona/sandbox-extra:0.1
cpuSandbox 分配的 CPU 核数2
memory内存大小 (GB)4
disk磁盘大小 (GB)10
sandboxClassSandbox 类型container

3.5 查看 Snapshot 状态

curl -s http://localhost:3000/api/snapshots -H "Authorization: Bearer $TOKEN" -H "X-Daytona-Organization-ID: $ORG_ID" | jq '.items[] | {name, state, size, errorReason}'

可能的状态流转:

pendingpullingactive ✅ (成功)
pendingpullingerror ❌ (失败,查看 errorReason)

3.6 删除 Snapshot(如需重试)

SNAPSHOT_ID="<snapshot-id>"curl -s -X DELETE "http://localhost:3000/api/snapshots/$SNAPSHOT_ID" -H "Authorization: Bearer $TOKEN" -H "X-Daytona-Organization-ID: $ORG_ID"

4. 方式二:通过 Web Dashboard 操作

4.1 登录 Dashboard

  1. 浏览器打开 http://localhost:3000/dashboard
  2. 使用 [email protected] / password 登录
  3. Dex 会重定向回 Dashboard

4.2 推送镜像到 Registry(前提)

无论哪种方式,都需要先将镜像推送到本地 Registry:

docker tag sandbox-extra:0.1 localhost:6000/daytona/sandbox-extra:0.1docker push localhost:6000/daytona/sandbox-extra:0.1

4.3 通过界面创建 Snapshot(推测)

  1. 登录 Dashboard 后,找到 Snapshots(快照)管理页面
  2. 点击 Create Snapshot(创建快照)
  3. 填写以下信息:
    • Name: sandbox-extra
    • Image Name: registry:6000/daytona/sandbox-extra:0.1
      • ⚠️ 必须用容器内部地址 registry:6000,不能用 localhost:6000
    • CPU / Memory / Disk: 按需设置
  4. 点击 Create(创建)
  5. 等待状态从 pendingpullingactive

4.4 Registry UI 查看镜像

另外,可以通过 Registry UI 查看已推送的镜像:

  • 地址:http://localhost:5100
  • 可以查看 daytona/sandbox-extra 仓库及其标签

5. 方式三:通过 Daytona CLI 操作(开发中)

Daytona CLI (daytona) 当前版本 (v0.190.0) 主要用于服务端管理和 Sandbox 交互,暂未提供直接的 snapshot 管理命令。

# 查看 CLI 当前可用的命令daytona --help

如果需要从 CLI 操作,可考虑使用 curl 封装脚本(见方式一)。

6. 踩坑记录

坑 1:localhost:6000 vs registry:6000(最重要!)

❌ 错误做法:

# 创建 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 会去拉取镜像,所以要用 容器内部网络 的地址。

坑 2:API Key 权限不足

❌ 错误做法:

# 直接用 API Key 调用 POST /api/snapshotsAuthorization: Bearer dtn_b4b9e38cfcc3677bae7d72dc0812ecf7dacdb5534789e9ce2d1b89bf605d1132

❌ 报错信息:

403 Forbidden: Access denied

原因: 创建 snapshot 需要 write:snapshots 权限,而 API Key 默认可能没有此权限。

✅ 解决方法: 使用 JWT Token(通过 Web 登录获取)代替 API Key。

坑 3:Dex 不支持 password grant type

❌ 错误做法:

curl -X POST http://localhost:5556/dex/token -d "grant_type=password&client_id=daytona&[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。

坑 4:相同的 name 不能重复创建

第一次失败后需要先删除再重新创建,否则创建会失败。

7. 后续升级镜像的标准操作流程

当构建了新的 sandbox-extra:0.2(或更新版本)时,按以下步骤操作:

Step 1: 构建新版本镜像

# 在你的构建目录下cd /root/daytona-sandbox-extra./build.sh# 或其他构建命令

Step 2: 推送新版本到 Registry

# 打标签docker tag sandbox-extra:0.2 localhost:6000/daytona/sandbox-extra:0.2# 推送到 Registrydocker push localhost:6000/daytona/sandbox-extra:0.2

Step 3: 通过 Dashboard 创建新 Snapshot

  1. 登录 http://localhost:3000/dashboard
  2. 进入 Snapshots 管理页面
  3. 点击 Create Snapshot
  4. 填写:
    • Name: sandbox-extra-v2(或不同的名称)
    • Image Name: registry:6000/daytona/sandbox-extra:0.2
    • Resource: 按需设置
  5. 点击创建,等待状态变为 active

Step 4(可选): 通过 API 创建

JWT="<你的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 .

完整一键脚本

#!/bin/bash# 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

8. 常见问题 FAQ

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 部署

最新游戏

更多

Copyright©2010-2019. All rights reserved | 波波三国游戏官网|[email protected]

备案编号:湘ICP备2022015115号-4