我在 Azure 中创建了一个容器实例并使用了 Hello World 映像。但是,我没有任何 IP 来访问网络服务器!
2 回答
TL;博士。您可能希望使用 CLI(或其他方法)来部署 ACI。请务必设置--ip_address public
或--dns-name-label <blah>
以创建公共 IP 地址。
例子:
az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label aci-demo --ports 80
参考:https ://docs.microsoft.com/en-us/azure/container-instances/container-instances-quickstart
调查细节:通过 Azure 门户部署 ACI 时,我能够重现相同的问题。我的猜测是:Azure 门户存在一个错误,它没有将公共 IP / DNS 标签发送到 Azure 控制平面,因此没有创建公共 IP 地址。
在此屏幕截图中,我还提供了 DNS 名称标签并将 IP 地址设置为公共,我们可以查看 ARM 模板门户使用情况。
ARM 模板如下所示,您可以在其中看到dnsNameLabel
被定义为参数,但在资源创建部分中没有被引用/应用
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"containerName": {
"type": "string"
},
"imageType": {
"type": "string",
"allowedValues": [
"Public",
"Private"
]
},
"imageName": {
"type": "string"
},
"osType": {
"type": "string",
"allowedValues": [
"Linux",
"Windows"
]
},
"numberCpuCores": {
"type": "string"
},
"memory": {
"type": "string"
},
"restartPolicy": {
"type": "string",
"allowedValues": [
"OnFailure",
"Always",
"Never"
]
},
"ports": {
"type": "array"
},
"dnsNameLabel": {
"type": "string"
}
},
"resources": [
{
"location": "[parameters('location')]",
"name": "[parameters('containerName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-07-01",
"properties": {
"containers": [
{
"name": "[parameters('containerName')]",
"properties": {
"image": "[parameters('imageName')]",
"resources": {
"requests": {
"cpu": "[int(parameters('numberCpuCores'))]",
"memoryInGB": "[float(parameters('memory'))]"
}
},
"ports": "[parameters('ports')]"
}
}
],
"restartPolicy": "[parameters('restartPolicy')]",
"osType": "[parameters('osType')]"
},
"tags": {}
}
]
}
我已经在我的环境中测试过了。
我按照此文档快速入门 - 将 Docker 容器部署到容器实例 - 门户 - Azure 容器实例 | Microsoft Docs通过 azure 门户创建容器实例。
但是从门户创建容器的问题是创建容器实例后 IP 地址和 FQDN 为空白。通过门户创建容器实例可能存在一些问题
我按照本文档快速入门 - 将 Docker 容器部署到容器实例 - Azure CLI - Azure 容器实例 |使用 CLI 创建了另一个容器实例 微软文档
使用 IP 地址和 FQDN 成功创建容器实例。
因此,我们可以使用 CLI 创建容器实例来解决问题。