Azure 容器组 2 个容器,带有 2 个外部端口。第二个容器总是终止
Azure container group 2 containers with 2 external ports. 2nd container always terminates
我正在尝试部署具有多个外部端口的 Azure 容器实例。我尝试了以下地形代码:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "experiment" {
name = "experiment"
location = "west europe"
}
resource "azurerm_container_group" "nginx" {
name = "nginx-test-terraform"
location = azurerm_resource_group.experiment.location
resource_group_name = azurerm_resource_group.experiment.name
os_type = "Linux"
ip_address_type = "public"
dns_name_label = "nginx-test-terraform"
container {
name = "nginx"
image = "nginx"
cpu = "0.5"
memory = "0.5"
ports {
port = 80
protocol = "TCP"
}
}
container {
name = "nginx2"
image = "nginx"
cpu = "0.5"
memory = "0.5"
ports {
port = 81
protocol = "TCP"
}
}
}
但是,第二个容器总是失败并出现以下错误:
[emerg] 1#1: bind() 到 0.0.0.0:80 失败(98:地址已被使用)
我是否可以在文件中更正此问题,或者这是目前 Terraform 的限制?
我对 Yaml 文件进行了同样的尝试:
apiVersion: 2018-10-01
name: dockercompose-exp-01
location: westeurope
type: Microsoft.ContainerInstance/containerGroups
properties:
osType: Linux
restartPolicy: Always
containers:
- name: helloworld-ms
properties:
image: mcr.microsoft.com/azuredocs/aci-helloworld
resources:
requests:
cpu: 0.5
memoryInGB: 0.5
ports:
- port: 80
protocol: TCP
- name: helloworld-nginx
properties:
image: nginx
resources:
requests:
cpu: 0.5
memoryInGB: 0.5
ports:
- port: 81
protocol: TCP
ipAddress:
ports:
- port: 80
protocol: TCP
- port: 81
protocol: TCP
type: Public
dnsNameLabel: dockercompose-exp-01
同样的事情发生了。
因此,这似乎是平台的限制,或者我遇到了某种语法错误。
如有任何帮助,我们将不胜感激。
实际上,ACI不支持端口映射。您只能直接公开端口。而且端口是独一无二的。
所以你犯的错误是Nginx镜像在Dockerfile中暴露了80端口,而你想为第二个暴露81端口。然后81端口无法响应。我建议不要在一个容器组中部署同一个镜像,没用的。
我正在尝试部署具有多个外部端口的 Azure 容器实例。我尝试了以下地形代码:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "experiment" {
name = "experiment"
location = "west europe"
}
resource "azurerm_container_group" "nginx" {
name = "nginx-test-terraform"
location = azurerm_resource_group.experiment.location
resource_group_name = azurerm_resource_group.experiment.name
os_type = "Linux"
ip_address_type = "public"
dns_name_label = "nginx-test-terraform"
container {
name = "nginx"
image = "nginx"
cpu = "0.5"
memory = "0.5"
ports {
port = 80
protocol = "TCP"
}
}
container {
name = "nginx2"
image = "nginx"
cpu = "0.5"
memory = "0.5"
ports {
port = 81
protocol = "TCP"
}
}
}
但是,第二个容器总是失败并出现以下错误:
[emerg] 1#1: bind() 到 0.0.0.0:80 失败(98:地址已被使用)
我是否可以在文件中更正此问题,或者这是目前 Terraform 的限制?
我对 Yaml 文件进行了同样的尝试:
apiVersion: 2018-10-01
name: dockercompose-exp-01
location: westeurope
type: Microsoft.ContainerInstance/containerGroups
properties:
osType: Linux
restartPolicy: Always
containers:
- name: helloworld-ms
properties:
image: mcr.microsoft.com/azuredocs/aci-helloworld
resources:
requests:
cpu: 0.5
memoryInGB: 0.5
ports:
- port: 80
protocol: TCP
- name: helloworld-nginx
properties:
image: nginx
resources:
requests:
cpu: 0.5
memoryInGB: 0.5
ports:
- port: 81
protocol: TCP
ipAddress:
ports:
- port: 80
protocol: TCP
- port: 81
protocol: TCP
type: Public
dnsNameLabel: dockercompose-exp-01
同样的事情发生了。
因此,这似乎是平台的限制,或者我遇到了某种语法错误。
如有任何帮助,我们将不胜感激。
实际上,ACI不支持端口映射。您只能直接公开端口。而且端口是独一无二的。
所以你犯的错误是Nginx镜像在Dockerfile中暴露了80端口,而你想为第二个暴露81端口。然后81端口无法响应。我建议不要在一个容器组中部署同一个镜像,没用的。