Home > Mobile >  Specify port while deploying a Docker container for Terraform Provider for Azure
Specify port while deploying a Docker container for Terraform Provider for Azure

Time:06-22

I am trying to follow the example of a Linux App Service running a Docker container.

This is my 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"
    }
  }
}

I am able to perform terraform init and terraform apply successfully. However I am not able to access the application. I also see that the running port is missing from the above Terraform configuration. How can we add that and make it work?

Locally I can take the Docker image for a run like:

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

What shall I do to deploy this over App Service using Terraform?

CodePudding user response:

App Service listens on port 80. To route the traffic to port 8080, the one that your container is listening on, add the following to the app_settings section:

WEBSITES_PORT = 8080
  • Related