如何使用最新Docker在ACI部署镜像?Docker CLI已移除公有云支持
部署Docker镜像到Azure Container Instance(ACI)的替代方案
既然Docker CLI已经移除了公有云部署支持,你可以用下面几种官方推荐的方案完成部署:
1. 使用Azure CLI(最常用的命令行方式)
这是Azure官方主推的命令行工具,步骤简单直接:
- 首先登录Azure账号:
az login - 直接部署Docker Hub公开镜像:
az container create \ --resource-group <你的资源组名称> \ --name <ACI实例名称> \ --image <镜像名,比如nginx:latest> \ --ports 80 \ --ip-address Public - 如果是私有镜像(比如Azure容器注册表ACR中的镜像),需添加注册表登录信息:
az container create \ --resource-group <资源组名称> \ --name <ACI实例名称> \ --image <ACR登录服务器>/<镜像名>:<标签> \ --registry-login-server <ACR登录服务器> \ --registry-username <ACR用户名> \ --registry-password <ACR密码> \ --ports 80 \ --ip-address Public
部署完成后,用az container show --resource-group <资源组> --name <实例名>查看状态和访问地址。
2. 通过Azure Portal可视化部署
适合不熟悉命令行的场景:
- 登录Azure Portal,搜索并进入「Container Instances」服务
- 点击「创建」,进入创建向导:
- 基本信息:选择订阅、资源组,填写实例名称、区域
- 容器配置:选择镜像来源(Docker Hub/ACR/私有注册表),输入镜像地址,配置CPU、内存资源
- 网络:设置公共IP(如需外部访问),开放对应端口
- 验证配置无误后,点击「创建」等待部署完成
3. 使用Terraform(基础设施即代码)
适合自动化、批量部署场景,先确保已安装Terraform并完成Azure认证:
- 创建
main.tf配置文件:provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "example-resources" location = "East US" } resource "azurerm_container_group" "example" { name = "example-container-group" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name ip_address_type = "Public" dns_name_label = "example-container" os_type = "Linux" container { name = "nginx" image = "nginx:latest" cpu = 1 memory = 1.0 ports { port = 80 protocol = "TCP" } } } - 执行部署命令:
terraform init terraform plan terraform apply
4. 使用Azure Bicep(微软原生IaC工具)
比ARM模板更简洁易读,示例main.bicep文件:
resource rg 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'example-rg' location: 'East US' } resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = { name: 'example-cg' location: rg.location properties: { containers: [ { name: 'nginx-container' properties: { image: 'nginx:latest' resources: { requests: { cpu: 1 memoryInGB: 1 } } ports: [ { port: 80 protocol: 'TCP' } ] } } ] osType: 'Linux' ipAddress: { type: 'Public' ports: [ { port: 80 protocol: 'TCP' } ] } } }
- 部署命令:
az deployment group create --resource-group <资源组名称> --template-file main.bicep
额外注意事项
- 私有镜像需确保ACI有权限拉取:ACR可启用「管理员账户」或配置服务主体权限;Docker Hub私有镜像需提供用户名和密码
- 注意ACI的区域资源配额,CPU、内存超出上限会导致部署失败
- 如需VNet集成、环境变量、挂载卷等高级配置,可在对应命令或配置中添加参数
内容的提问来源于stack exchange,提问作者Abhishek Tripathi
相关产品推荐
相关产品推荐

