What is the correct way to deploy an nginx container on azure app service?

Viewed 643

I built a react app and I created a docker file that uses the nginx image. I can build and run the docker container locally and it serves up my react app sucessfully. However when I try and deploy this to azure app service it is failing for some reason. In the logs in logstream it just says "Your container failed to start up" What confuses me is that I am deploying this in a very similar way to how I have successfully deployed hundreds of java containers running springboot apps. In this situation I have no problem, but for some reason it is taking me days to get this nginx/react app working on app service.

I am provisioning the app service with terraform. The code looks like this.

resource "azurerm_app_service_plan" "dpt_appservice_plan" {
  name                = "${var.ENVIRONMENT}-dpt-app-service-plan"
  location            = azurerm_resource_group.dpt_rg.location
  resource_group_name = azurerm_resource_group.dpt_rg.name
  kind                = "Linux"
  reserved            = true

  sku {
    tier = "Basic"
    size = "S1"
  }
}

resource "azurerm_app_service" "dpt_my_website_app_service" {
  name = "${var.ENVIRONMENT}-dpt-my-website-app-service"
  location = azurerm_resource_group.dpt_rg.location
  resource_group_name = azurerm_resource_group.dpt_rg.name
  app_service_plan_id = azurerm_app_service_plan.dpt_appservice_plan.id

  site_config {
    always_on = false
    linux_fx_version = "DOCKER|${var.ENVIRONMENT}<acr>.azurecr.io/<registry>:latest"
  }

  app_settings = {
    DOCKER_REGISTRY_SERVER_URL = "https:# acr.azurecr.io"
    DOCKER_REGISTRY_SERVER_USERNAME = azurerm_container_registry.dpt_acr.admin_username
    DOCKER_REGISTRY_SERVER_PASSWORD = azurerm_container_registry.dpt_acr.admin_password
    WEBSITES_PORT = 8080
    WEBSITES_CONTAINER_START_TIME_LIMIT = 300
  }
}

I build the react app and take the contents from the build directory and place them in the nginx container

FROM nginx
COPY build /usr/share/nginx/html
COPY docker/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 8080 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Does anybody know the correct way to deploy an nginx container with a react app to azure app service?

1 Answers

All of the code there was posted there is correct. I solved this issue by changing the azure-pipelines file. Before the containerCommand was uncommented. For some reason with the nginx container the containerCommand should not be included as it just magically starts up but when you add this like I did then it makes it fail. I commented it out by adding the # sign next to it.

    inputs:
      azureSubscription: 'dpt-service-1'
      appName: 'dev-dpt-my-website-app-service'
      deployToSlotOrASE: true
      resourceGroupName: 'dev-dpt-rg'
      # Do not set this to production only use slot<number>
      slotName: 'production'
      imageName: 'devdptAcr.azurecr.io/dpt-images:$(smallTag)'
#      containerCommand: 'docker run -p 80:80 $(smallTag)'
Related