Docker-Compose构建的多容器应用本地正常,部署Azure App Service失败
问题分析与解决方案
错误原因
Azure App Service 多容器部署不支持 docker-compose 中的 build 字段,且本地文件挂载的 volumes 配置在 Azure 沙箱环境中无法正常解析,YAML 解析器因此遇到非预期的节点类型,导致启动失败。
修复步骤
1. 重新构建并推送镜像到 Azure Container Registry (ACR)
先在本地构建两个服务的镜像,推送到你的 ACR 仓库:
# 构建 rasa 镜像并推送 docker build -t <你的ACR名称>.azurecr.io/rasa-server:latest . docker push <你的ACR名称>.azurecr.io/rasa-server:latest # 构建 action_server 镜像并推送 docker build -t <你的ACR名称>.azurecr.io/action-server:latest ./actions docker push <你的ACR名称>.azurecr.io/action-server:latest
2. 修改 docker-compose.yaml 配置
移除不兼容的 build 和本地挂载 volumes,替换为 ACR 镜像地址:
version: '3.8' services: rasa: container_name: "rasa_server" user: root image: <你的ACR名称>.azurecr.io/rasa-server:latest ports: - "80:80" restart: always action_server: container_name: "action_server" image: <你的ACR名称>.azurecr.io/action-server:latest ports: - "5055:5055" restart: always
可选:如果需要持久化数据
若应用依赖 data 目录的持久化存储,可使用 Azure 文件共享挂载:
version: '3.8' services: rasa: container_name: "rasa_server" user: root image: <你的ACR名称>.azurecr.io/rasa-server:latest ports: - "80:80" restart: always action_server: container_name: "action_server" image: <你的ACR名称>.azurecr.io/action-server:latest ports: - "5055:5055" volumes: - azure-data:/app/data restart: always volumes: azure-data: driver: azure_file driver_opts: share_name: <你的文件共享名称> storage_account_name: <你的存储账户名称>
3. 验证 YAML 格式
确保配置文件使用空格缩进(不要用制表符),避免语法错误导致解析失败。
4. 重新部署到 Azure App Service
- 在 App Service 容器设置中选择「多容器」模式
- 上传修改后的 docker-compose.yaml
- 确认 App Service 已配置 ACR 访问权限(可通过服务主体或管理员账户授权)
内容的提问来源于stack exchange,提问作者Shaida Muhammad
相关产品推荐
相关产品推荐

