如何在Azure容器实例上公开多个端口? [英] How to expose multiple ports on Azure Container Instance?

查看:71
本文介绍了如何在Azure容器实例上公开多个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我想运行以下命令: docker run -p 80: 80 -p 443:443 ...

我尝试失败:


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

  • 语法错误: az容器创建... --port 80443

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

但是资源JSON似乎表明可以使用数组:

But the resource JSON seems to indicate that an 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"
      }
    ]
  },
  ...
}


推荐答案

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

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

部署模板:

> https://docs.microsoft.com/zh-cn/azure/azure-resource-manager/resource-manager-create-first- template#deploy-template

这篇关于如何在Azure容器实例上公开多个端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆