Deploy to an Azure Web App for Containers

VSTS

We'll show you how to set up continuous deployment of your Docker-enabled app to an Azure web app using Visual Studio Team Services (VSTS).

For example, you can continuously deliver your app to a Windows VM hosted in Azure.

A typical release pipeline for web applications

After you commit and push a code change, it is automatically built and then deployed. The results will automatically show up on your site.

Define your CI build process

You'll need a continuous integration (CI) build process that publishes a Docker container image. To set up a CI build process, see:

Prerequisites

You'll need an Azure subscription. You can get one free through Visual Studio Dev Essentials.

Create an Azure web app to host a container

  1. Sign into your Azure Account at https://portal.azure.com.

  2. In the Azure Portal, choose New, Web + Mobile, then choose Web App for Containers.

  3. Enter a name for your new web app, and select or create a new Resource Group. Then choose Configure container and select Azure Container Registry. Use the drop-down lists to select the registry you created earlier, and the Docker image and tag that was generated by the build definition.

    Creating the Web App for Containers

    The Docker tasks you used in the build definition when you created the build artifacts push the Docker image back into your Azure Container Registry. The web app you created here will host an instance of that image and expose it as a website.

  4. Wait until the new web app has been created.

    You can configure the web app for containers to automatically configure deployment as part of the CI/CD process so that the web app is automatically updated when a new image is pushed to the container. However, by using a separate release definition in VSTS or TFS you gain extra flexibility. You can:

    • Specify a tag that is used to select the deployment target for multi-environment deployments.
    • Use separate container registries for different environments.
    • Use parameterized start-up commands to, for example, set the values of variables based on the target environment.

Create a release definition

  1. In the Build & Release hub, open the build summary for your build.

    Opening the build summary

  2. In the build summary page, choose the Release icon to start a new release definition.

    Starting a new release definition from a build summary

    If you have previously created a release definition that uses these build artifacts, you will be prompted to create a new release instead. In that case, go to the Releases tab page and start a new release definition from there by choosing the + icon.

  3. Select the Azure App Service Deployment task and choose Apply.

    Adding the App Service Deployment task

  4. Open the Tasks tab and select the Azure App Service Deployment task. Configure the properties as follows:

    • Azure Subscription: Select a connection from the list under Available Azure Service Connections or create a more restricted permissions connection to your Azure subscription. If you are using VSTS and if you see an Authorize button next to the input, click on it to authorize VSTS to connect to your Azure subscription. If you are using TFS or if you do not see the desired Azure subscription in the list of subscriptions, see Azure Resource Manager service endpoint to manually set up the connection.

      Authorizing an Azure subscription

    • App Service Name: Select the name of the web app from your subscription.

    When you select the Docker-enabled app service, the task recognizes that it is a containerized app, and changes the property settings to show the following:

    • Registry or Namespace: Enter the path to your Azure Container Registry. Typically this is your-registry-name.azurecr.io

    • Repository: Enter the name of your repository, which is typically the name of the app you started with.

    • Tag: Enter $(Build.BuildId). The tag that was created automatically is the build identifier.

      Configuring the App Service Deployment task

  5. Save the release definition.

Create a release to deploy your app

You're now ready to create a release, which means to start the process of running the release definition with the artifacts produced by a specific build. This will result in deploying the build:

  1. Choose + Release and select Create Release.

  2. In the Create new release dialog, check that the artifact version you want to use is selected and choose Queue.

  3. Choose the release link in the information bar message. For example: "Release Release-1 has been created".

  4. Open the Logs tab to watch the release console output.

  5. After the release is complete, navigate to your site running in Azure using the Web App URL http://{web_app_name}.azurewebsites.net, and verify its contents.

Next steps