ln-783-container-launcher
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseln-783-container-launcher
ln-783-容器启动器
Type: L3 Worker
Category: 7XX Project Bootstrap
Parent: ln-780-bootstrap-verifier
类型: L3 工作组件
分类: 7XX 项目启动工具集
父组件: ln-780-启动验证器
Purpose
用途
Builds Docker images, launches containers, and performs comprehensive health verification using Docker native health checks and retry strategies.
Scope:
- Detect and validate docker-compose.yml configuration
- Build Docker images
- Launch containers with proper startup order
- Verify container health using native health checks
- Provide access URLs and cleanup instructions
Out of Scope:
- Building application code (handled by ln-781)
- Running tests (handled by ln-782)
- Container orchestration beyond single host (Kubernetes, Swarm)
构建Docker镜像、启动容器,并利用Docker原生健康检查和重试策略执行全面的健康验证。
适用范围:
- 检测并验证docker-compose.yml配置
- 构建Docker镜像
- 按正确启动顺序启动容器
- 利用原生健康检查验证容器健康状态
- 提供访问URL和清理说明
不适用范围:
- 构建应用代码(由ln-781处理)
- 运行测试(由ln-782处理)
- 单主机之外的容器编排(如Kubernetes、Swarm)
When to Use
使用场景
| Scenario | Use This Skill |
|---|---|
| Called by ln-780 orchestrator | Yes |
| Standalone container launch | Yes |
| Development environment setup | Yes |
| Production deployment | No, use proper CI/CD |
| 场景 | 是否使用本组件 |
|---|---|
| 由ln-780编排器调用 | 是 |
| 独立启动容器 | 是 |
| 开发环境搭建 | 是 |
| 生产环境部署 | 否,使用专业CI/CD工具 |
Workflow
工作流程
Step 1: Pre-flight Checks
步骤1:预检检查
Verify Docker environment readiness.
| Check | Failure Action |
|---|---|
| Docker daemon running | Report error with installation instructions |
| Docker Compose available | Report error, suggest installation |
| Compose file exists | Report error, list expected locations |
| Required ports free | Report conflict, suggest alternatives |
| Sufficient disk space | Warn if low space (<2GB free) |
验证Docker环境是否就绪。
| 检查项 | 失败处理动作 |
|---|---|
| Docker守护进程是否运行 | 报错并提供安装启动说明 |
| Docker Compose是否可用 | 报错并建议安装 |
| Compose文件是否存在 | 报错并列出预期路径 |
| 所需端口是否空闲 | 报告端口冲突并建议替代方案 |
| 磁盘空间是否充足 | 空间不足时发出警告(剩余空间<2GB) |
Step 2: Parse Compose Configuration
步骤2:解析Compose配置
Extract service information from docker-compose.yml.
| Information | Purpose |
|---|---|
| Service names | Track which containers to monitor |
| Exposed ports | Know which ports to check |
| Health check definitions | Use native health checks if defined |
| Dependencies (depends_on) | Understand startup order |
| Volume mounts | Verify paths exist |
从docker-compose.yml中提取服务信息。
| 信息内容 | 用途 |
|---|---|
| 服务名称 | 跟踪需要监控的容器 |
| 暴露端口 | 明确需要检查的端口 |
| 健康检查定义 | 若已定义则使用原生健康检查 |
| 依赖关系(depends_on) | 明确启动顺序 |
| 卷挂载 | 验证挂载路径是否存在 |
Step 3: Build Images
步骤3:构建镜像
Build all images defined in compose file.
| Aspect | Strategy |
|---|---|
| Build context | Use paths from compose file |
| Build args | Pass through from compose configuration |
| Cache | Use Docker layer cache for speed |
| Failure | Report build errors with full log |
构建Compose文件中定义的所有镜像。
| 方面 | 策略 |
|---|---|
| 构建上下文 | 使用Compose文件中指定的路径 |
| 构建参数 | 直接传递Compose配置中的参数 |
| 缓存 | 利用Docker层缓存提升速度 |
| 失败处理 | 报错并提供完整构建日志 |
Step 4: Launch Containers
步骤4:启动容器
Start containers with proper orchestration.
| Aspect | Strategy |
|---|---|
| Startup order | Respect depends_on and healthcheck conditions |
| Detached mode | Run in background |
| Network | Use compose-defined networks |
| Volumes | Mount all defined volumes |
按合理编排逻辑启动容器。
| 方面 | 策略 |
|---|---|
| 启动顺序 | 遵循depends_on和健康检查条件 |
| 后台模式 | 在后台运行容器 |
| 网络 | 使用Compose定义的网络 |
| 卷 | 挂载所有已定义的卷 |
Step 5: Health Verification
步骤5:健康验证
Verify all containers are healthy using appropriate strategy.
Strategy Selection:
| Condition | Strategy |
|---|---|
Service has | Use native Docker health status |
Service has | Wait for Docker health status |
| No healthcheck defined | Use external HTTP probe with retry |
Retry Configuration:
| Parameter | Value | Rationale |
|---|---|---|
| Max attempts | 10 | Allow slow-starting services |
| Initial delay | 5s | Give containers time to start |
| Backoff | Exponential (5, 10, 20, 40s) | Avoid overwhelming services |
| Max total wait | 120s | Reasonable upper limit |
Health Check Methods:
| Method | When to Use |
|---|---|
| Docker health status | When container has healthcheck defined |
| HTTP GET to exposed port | For web services without healthcheck |
| Container exec | For services without exposed ports |
| TCP port check | For databases and message queues |
采用合适策略验证所有容器是否健康。
策略选择:
| 条件 | 策略 |
|---|---|
服务在Compose中定义了 | 使用Docker原生健康状态 |
服务定义了 | 等待Docker健康状态 |
| 未定义健康检查 | 使用外部HTTP探测并重试 |
重试配置:
| 参数 | 取值 | 理由 |
|---|---|---|
| 最大尝试次数 | 10 | 为启动较慢的服务预留时间 |
| 初始延迟 | 5秒 | 给容器启动预留时间 |
| 退避策略 | 指数退避(5、10、20、40秒) | 避免压垮服务 |
| 最长总等待时间 | 120秒 | 合理的上限值 |
健康检查方法:
| 方法 | 使用场景 |
|---|---|
| Docker健康状态 | 容器已定义健康检查时 |
| 向暴露端口发送HTTP GET请求 | 无健康检查的Web服务 |
| 容器内执行命令 | 无暴露端口的服务 |
| TCP端口检查 | 数据库和消息队列服务 |
Step 6: Report Results
步骤6:结果报告
Return structured results to orchestrator.
Result Structure:
| Field | Description |
|---|---|
| containers | Array of container status objects |
| healthChecks | Array of health check results |
| accessUrls | Map of service name to access URL |
| overallStatus | healthy / unhealthy / partial |
| startupDuration | Time from launch to all healthy |
Container Status Object:
| Field | Description |
|---|---|
| name | Container name |
| service | Service name from compose |
| status | running / exited / restarting |
| health | healthy / unhealthy / starting / none |
| port | Exposed port (if any) |
| startedAt | Container start timestamp |
Health Check Result:
| Field | Description |
|---|---|
| url | Checked URL or endpoint |
| status | HTTP status code or check result |
| responseTime | Time to respond in ms |
| healthy | Boolean health status |
向编排器返回结构化结果。
结果结构:
| 字段 | 描述 |
|---|---|
| containers | 容器状态对象数组 |
| healthChecks | 健康检查结果数组 |
| accessUrls | 服务名称到访问URL的映射 |
| overallStatus | 健康/不健康/部分健康 |
| startupDuration | 从启动到全部健康的耗时 |
容器状态对象:
| 字段 | 描述 |
|---|---|
| name | 容器名称 |
| service | Compose中的服务名称 |
| status | 运行中/已退出/重启中 |
| health | 健康/不健康/启动中/无健康检查 |
| port | 暴露端口(如有) |
| startedAt | 容器启动时间戳 |
健康检查结果:
| 字段 | 描述 |
|---|---|
| url | 检查的URL或端点 |
| status | HTTP状态码或检查结果 |
| responseTime | 响应时间(毫秒) |
| healthy | 健康状态布尔值 |
Error Handling
错误处理
| Error Type | Action |
|---|---|
| Docker daemon not running | Report with start instructions |
| Port already in use | Report conflict, suggest docker compose down first |
| Image build failed | Report with build logs |
| Container exited | Report with container logs |
| Health check timeout | Report with last known status and logs |
| Network unreachable | Check Docker network configuration |
| 错误类型 | 处理动作 |
|---|---|
| Docker守护进程未运行 | 报错并提供启动说明 |
| 端口已被占用 | 报告冲突并建议先执行docker compose down |
| 镜像构建失败 | 报错并提供构建日志 |
| 容器已退出 | 报错并提供容器日志 |
| 健康检查超时 | 报错并提供最后已知状态和日志 |
| 网络不可达 | 检查Docker网络配置 |
Options
可选配置
| Option | Default | Description |
|---|---|---|
| keepRunning | true | Leave containers running after verification |
| stopAfter | false | Stop containers after successful verification |
| healthTimeout | 120 | Max seconds to wait for healthy status |
| showLogs | true | Show container logs on failure |
| buildFirst | true | Build images before starting |
| pullLatest | false | Pull base images before build |
| 选项 | 默认值 | 说明 |
|---|---|---|
| keepRunning | true | 验证完成后保持容器运行 |
| stopAfter | false | 验证成功后停止容器 |
| healthTimeout | 120 | 等待健康状态的最长秒数 |
| showLogs | true | 失败时显示容器日志 |
| buildFirst | true | 启动前先构建镜像 |
| pullLatest | false | 构建前拉取最新基础镜像 |
Cleanup Instructions
清理说明
Provide user with cleanup commands in report.
| Action | Description |
|---|---|
| Stop containers | Stop running containers, preserve data |
| Remove containers and networks | Clean up containers but keep volumes |
| Remove everything | Full cleanup including volumes and images |
在报告中为用户提供清理命令。
| 操作 | 说明 |
|---|---|
| 停止容器 | 停止运行中的容器,保留数据 |
| 删除容器和网络 | 清理容器但保留卷 |
| 完全清理 | 清理所有内容,包括卷和镜像 |
Critical Rules
核心规则
- Use native health checks when available - more reliable than external probes
- Implement retry with backoff - services need time to initialize
- Always collect logs on failure - essential for debugging
- Parse compose file for ports - do not hardcode port numbers
- Respect depends_on order - critical for database-dependent services
- 优先使用原生健康检查 - 比外部探测更可靠
- 实现带退避的重试机制 - 服务需要时间初始化
- 失败时务必收集日志 - 对调试至关重要
- 从Compose文件解析端口 - 不要硬编码端口号
- 遵循depends_on顺序 - 对依赖数据库的服务至关重要
Definition of Done
完成标准
- Docker environment verified
- All images built successfully
- All containers running
- All health checks passing
- Access URLs provided
- Results returned to orchestrator
Version: 2.0.0
Last Updated: 2026-01-10
- Docker环境已验证
- 所有镜像构建成功
- 所有容器正在运行
- 所有健康检查通过
- 已提供访问URL
- 结果已返回给编排器
版本: 2.0.0
最后更新时间: 2026-01-10