How to open multiple ports in an Azure container instance?

Is it possible to open or open more than one port on an Azure container instance ? I managed to open only one port per container.

I would like to run the equivalent: docker run -p 80:80 -p 443:443 ...

I tried unsuccessfully:

  • Displays only the last port: az container create ... --port 80 --port 443
  • Syntax error: az container create ... --port 80 443

But the JSON resource seems to indicate that the array is possible:

 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" } ] }, ... } 
+7
azure azure-container-instances
source share
3 answers

Since the ports (specified [] ) property is an array, you can add a few 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

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

+1
source share

You can, but currently you can only do this with the Azure Resource Manager template. The CLI and the portal are focused on a simple case: one container in a group of containers and one open port in this container.

Here is an example of a resource section from an Azure resource manager template ( see full template ):

 "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" } ] } } } ] 

You can deploy the template using az group deployment create ( full documentation ):

 az group deployment create -n myDeployment --template-file azuredeploy.json --parameters @azuredeploy.parameters.json -g myResourceGroup 
+3
source share

This can now be done through the Azure CLI. Example below:

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

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

+3
source share

All Articles