You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Docker Compose部署到Azure ACI时多服务容器创建超时

问题描述

使用Docker Compose的ACI上下文部署容器到Azure时,3个服务的配置可正常运行,但扩展至6个服务后,容器长期处于创建状态,最终触发超时错误:

$ docker compose --verbose -f .\nodes-123.docker-compose.yaml up
 level=debug msg="Up on project with name \"lab01-blockchain\""
 [+] Running 1/7
  - Group lab01-blockchain  Created                                                                                                                                                    7.7s 
  - node1                   Creating                                                                                                                                                 900.0s
  - node2                   Creating                                                                                                                                                 900.0s 
  - node3                   Creating                                                                                                                                                 900.0s 
  - node4                   Creating                                                                                                                                                 900.0s 
  - node5                   Creating                                                                                                                                                 900.0s 
  - node6                   Creating                                                                                                                                                 900.0s 
 Future#WaitForCompletion: context has been cancelled: StatusCode=200 -- Original Error: context deadline exceeded

已尝试移除自定义网络配置,且单服务资源配置(0.5CPU、1G内存)未超出Azure配额(4CPU、16G RAM),--verbose日志未提供有效排查信息。

解决方案

1. 延长Docker Compose部署超时时间

默认超时时间不足以支撑6个服务的并发创建,通过环境变量调整超时:

# Windows PowerShell
$env:COMPOSE_HTTP_TIMEOUT=1800
docker compose --verbose -f .\nodes-123.docker-compose.yaml up

# Linux/macOS
export COMPOSE_HTTP_TIMEOUT=1800
docker compose --verbose -f ./nodes-123.docker-compose.yaml up

2. 分批次部署服务

Azure ACI对单资源组内的并发容器组创建有限制,分批次部署可避免触发该限制:

  • 先启动前3个服务:docker compose up node1 node2 node3
  • 等待服务完全启动后,再启动剩余服务:docker compose up node4 node5 node6

3. 排查镜像拉取问题

6个服务并发拉取镜像可能遇到速率限制或临时网络波动:

  • 确认Azure容器注册表(ACR)的访问权限正常,ACI上下文已配置拉取权限
  • 手动在Azure上测试镜像拉取,验证镜像完整性和拉取速度

4. 临时降低资源预留,减少调度压力

虽然总资源在配额内,并发调度6个服务可能触发ACI内部调度瓶颈,临时降低资源预留:

deploy:
  resources:
    limits:
      cpus: '0.50'
      memory: 1G
    reservations:
      cpus: '0.25'  # 降低CPU预留,减少调度负载
      memory: 512M

部署成功后再调整回原配置。

5. 用Azure CLI查看ACI详细状态

Docker Compose日志不够细致,直接通过Azure CLI获取容器组事件:

# 列出资源组内所有容器组
az container list --resource-group <你的资源组名称> -o table

# 查看单个容器组的创建事件
az container show --resource-group <你的资源组名称> --name node1 -o json | jq '.instanceView.events'

这些事件会显示容器创建失败的具体原因,比如资源不足、镜像拉取失败等。

6. 检查Azure区域资源可用性

部分区域可能临时存在容器实例资源短缺,可尝试在docker-compose中指定其他区域:

x-azure:
  location: eastus  # 替换为资源充足的区域

内容的提问来源于stack exchange,提问作者Bruno MC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 18:41:06