gpt4 book ai didi

azure - 为 Terraform Provider for Azure 部署 Docker 容器时指定端口

转载 作者:行者123 更新时间:2023-12-03 06:58:16 24 4
gpt4 key购买 nike

我正在尝试效仿a Linux App Service running a Docker container的例子.

这是我的main.tf:

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "${var.prefix}-resources"
location = var.location
}

resource "azurerm_service_plan" "example" {
name = "${var.prefix}-sp-zipdeploy"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
os_type = "Linux"
sku_name = "S1"
}


resource "azurerm_linux_web_app" "example" {
name = "${var.prefix}-example"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
service_plan_id = azurerm_service_plan.example.id

app_settings = {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
}

site_config {
application_stack {
docker_image = "ghcr.io/moja-global/rest_api_flint.example"
docker_image_tag = "master"
}
}
}

我能够成功执行 terraform initterraform apply。但是我无法访问该应用程序。我还发现上述 Terraform 配置中缺少运行端口。我们如何添加它并使其发挥作用?

在本地,我可以使用 Docker 镜像进行运行,如下所示:

docker pull ghcr.io/moja-global/rest_api_flint.example:master
docker run --rm -p 8080:8080 ghcr.io/moja-global/rest_api_flint.example

我应该如何使用 Terraform 通过应用服务部署它?

最佳答案

应用服务监听端口 80。要将流量路由到容器正在监听的端口 8080,请将以下内容添加到 app_settings 部分:

WEBSITES_PORT = 8080

关于azure - 为 Terraform Provider for Azure 部署 Docker 容器时指定端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72705694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com