How to expose multiple ports on Azure Container Instance?

前端 未结 4 2240
故里飘歌
故里飘歌 2021-02-08 01:04

Is it possible to expose/open more than one port on an Azure Container Instance? I\'ve only been able to open one port per container.

I\'d like to run the equivalent of:

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 01:43

    Since ports ( indicated by [] ) property is an array you can add more elements to it:

    {
      "$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

    Deploy template:
    https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-create-first-template#deploy-template

提交回复
热议问题