12

是否可以在Azure 容器实例上公开/打开多个端口?我只能为每个容器打开一个端口。

我想运行相当于:docker run -p 80:80 -p 443:443 ...

我没有成功尝试过:

  • 仅映射最后一个端口:az container create ... --port 80 --port 443
  • 语法错误:az container create ... --port 80 443

但是资源 JSON 似乎表明一个数组是可能的:

az container show -name <container-name> --resource-group <resource-group-name>

Response: 
{
  "containers": [
    {
      ...
      "name": "...",
      "ports": [
        {
          "port": 80
        }
      ...
    }
  ],
   ...
  "ipAddress": {
    "ip": "xxx.xxx.xxx.xxx",
    "ports": [
      {
        "port": 80,
        "protocol": "TCP"
      }
    ]
  },
  ...
}
4

4 回答 4

22

这现在可以通过 Azure CLI 完成。示例如下:

az container create -g MyResourceGroup --name myalpine --image alpine:latest --ip-address public --ports 80 443

https://docs.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az_container_create

于 2018-02-08T22:35:10.047 回答
6

由于ports(由 表示[])属性是一个数组,您可以向其中添加更多元素:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {    
    "name": {
        "type": "string",
        "defaultValue": "acilinuxpublicipcontainergroup"
    },    
    "image": {        
        "type": "string",
        "defaultValue": "microsoft/aci-helloworld"
    },
    "port": {
        "type": "string",
        "defaultValue": "80"
    },    
    "cpuCores": {
        "type": "string",
        "defaultValue": "1.0"
    },
    "memoryInGb": {
        "type": "string",
        "defaultValue": "1.5"
    }
  },
  "resources": [
    {
            "name": "[parameters('name')]",
            "type": "Microsoft.ContainerInstance/containerGroups",
            "apiVersion": "2017-08-01-preview",
            "location": "[resourceGroup().location]",
            "properties": {
                "containers": [
                    {
                        "name": "[parameters('name')]",
                        "properties": {
                            "image": "[parameters('image')]",
                            "ports": [
                                {
                                    "port": "[parameters('port')]" 
                                }
                            ],
                            "resources": {
                                "requests": {
                                    "cpu": "[parameters('cpuCores')]",
                                    "memoryInGb": "[parameters('memoryInGb')]"
                                }
                            }
                        }
                    }
                ],
                "osType": "Linux",
                "ipAddress": {
                    "type": "Public",
                    "ports": [
                        {
                            "protocol": "tcp",
                            "port": "[parameters('port')]"
                        },
                        {
                            "protocol": "tcp",
                            "port": "[parameters('port2')]"
                        }
                    ]
                 }
            }
        }
    ]
}

https://github.com/Azure/azure-quickstart-templates/tree/master/101-aci-linuxcontainer-public-ip

部署模板:
https ://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-create-first-template#deploy-template

于 2017-08-09T18:03:30.310 回答
5

可以,但目前只能使用 Azure 资源管理器模板。CLI 和门户都面向简单的情况:容器组中的一个容器,以及该容器中的一个公开端口。

这是来自 Azure 资源管理器模板的示例资源部分(请参阅完整模板):

"resources": [
{
        "name": "myContainerGroup",
        "type": "Microsoft.ContainerInstance/containerGroups",
        "apiVersion": "2017-08-01-preview",
        "location": "[resourceGroup().location]",
        "properties": {
            "containers": [
                {
                    "name": "myContainer",
                    "properties": {
                        "image": "seanmckenna/aci-helloworld-multiport",
                        "ports": [
                            {
                                "port": "80" 
                            },
                            {
                                "port": "443"
                            }
                        ],
                        "resources": {
                            "requests": {
                                "cpu": "1.0",
                                "memoryInGb": "1.5"
                            }
                        }
                    }
                }
            ],
            "osType": "Linux",
            "ipAddress": {
                "type": "Public",
                "ports": [
                    {
                        "protocol": "tcp",
                        "port": "80"
                    },
                    {
                        "protocol": "tcp",
                        "port": "443"
                    }
                ]
             }
        }
    }
]

az group deployment create您可以使用(完整文档)部署模板:

az group deployment create -n myDeployment --template-file azuredeploy.json --parameters @azuredeploy.parameters.json -g myResourceGroup
于 2017-08-16T19:56:01.527 回答
2

现在 Azure 门户提供了添加两个额外端口的方法。您只需在创建 ACI 时说“”以在配置中打开其他端口。见下图。

在此处输入图像描述

于 2018-09-24T09:08:56.323 回答