Search code examples
azureazure-bicep

Azure bicep - depoy new web app service that uses docker image


how do you deploy a azure web app that has docker private image?

i tried this but it throws error "The parameter LinuxFxVersion has an invalid value".

bicep file

//input parameters

resource appServicePlan 'Microsoft.Web/serverfarms@2020-12-01' = {
  dependsOn: [
    appConfiguration
  ]
  name: 'ASP-ap-${environment}-01'
  location: location
  sku: {
    name: 'F1'
    capacity: 1
  }
}


resource webApplication 'Microsoft.Web/sites@2022-09-01' = {
  name: 'wa-service-${environment}'
  location: location
  tags: commonTags
  kind: 'app,linux,container'
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      appSettings: [
        {
          name: 'DOCKER_REGISTRY_SERVER_URL'
          value: dockerRegistryUrl
        }
        {
          name: 'DOCKER_REGISTRY_SERVER_USERNAME'
          value: dockerRegistryUsername
        }
        {
          name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
          value: dockerRegistryPassword
        }
      ]
      linuxFxVersion: 'DOCKER|${imageName}' // problem with this line apparently
    }
  }
}

then make the call using azure cli

az deployment group create --resource-group rg-test --template-file .\test.bicep --mode Complete 

Solution

  • The parameter LinuxFxVersion has an invalid value: -

    You need to check below points to resolve this error:

    1. The above error means that the parameter LinuxFxVersion is not properly given. It must be in the format of 'Docker|<Imagename>'. Verify the given image format once again and redeploy it.

    2. When deploying using a private registry, you must ensure that the Docker image is available in the private registry and that the registry credentials are stored in environment variables. You can access it using below url.

    https://<appsample>.scm.azurewebsites.net/Env

    enter image description here

    1. You need to pass kind: 'linux' instead kind: 'app,linux,container' when deploying a Linux runtime docker web apps as @Thomas given in comments.

    After checking all the above, I tried deploying a web app with a docker image and was able to deploy it successfully.

    param  appServicePlanName  string = 'containersample'
    param  location  string = 'EastUs'
    param  webAppName  string = 'Dockerappsample'
    param  registryName  string = 'alpine'
    param  dockerRegistryUserName  string = 'jahnavialias'
    resource  appServicePlan  'Microsoft.Web/serverfarms@2020-12-01' = {
       name: appServicePlanName
       location: location
       kind: 'linux'
       properties: {
          reserved: true
      }
    sku: {
       name: 'B1'
       tier: 'Basic'
      }
    }
    resource  webApp  'Microsoft.Web/sites@2021-01-01' = {
        name: webAppName
        location: location
        properties: {
        siteConfig: {
        appSettings: [ {
           name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
           value: 'xxxxx'
       }
       {
          name: 'DOCKER_REGISTRY_SERVER_URL'
          value: '${registryName}.azurecr.io'
       }
       {
          name: 'DOCKER_REGISTRY_SERVER_USERNAME'
          value: dockerRegistryUserName
       }]
       linuxFxVersion: 'DOCKER|${registryName}.azurecr.io:myimage:latest'
       }
       serverFarmId: appServicePlan.id
        }
    }
    

    Deployment succeeded:

    enter image description here

    enter image description here

    References:

    • MSDoc on how to build and run a custom image.
    • A Blog by @Sam Cogan for all the container related deployments of web app with bicep.