Skip to content

Latest commit

 

History

History
80 lines (57 loc) · 6.5 KB

File metadata and controls

80 lines (57 loc) · 6.5 KB

Azure Web App with Custom Docker Image

This sample demonstrates a Python Flask web application hosted on an Azure Web App using a custom Docker image. The app runs on an Azure App Service Plan and uses a container image stored in an Azure Container Registry. For more information on configuring a web app to use a custom container, see Configure a custom container for Azure App Service.

Architecture

The following diagram illustrates the architecture of the solution:

Architecture Diagram

The solution is composed of the following Azure resources:

  1. Azure Resource Group: A logical container scoping all resources in this sample.
  2. Azure Virtual Network: Hosts two subnets:
  3. Azure Private DNS Zone: Handles DNS resolution for the Azure Container Registry Private Endpoint within the virtual network.
  4. Azure Private Endpoint: Secures network access to the Azure Container Registry via a private IP within the VNet.
  5. Azure NAT Gateway: Provides deterministic outbound connectivity for the Web App. Included for completeness; the sample app does not call any external services.
  6. Azure Network Security Group: Enforces inbound and outbound traffic rules across the virtual network's subnets.
  7. Azure Log Analytics Workspace: Centralizes diagnostic logs and metrics from all resources in the solution.
  8. Azure Container Registry: A fully-managed container registry service based on the open-source Docker platform used to hold the container image used by the web app.
  9. User-Assigned Managed Identity: Assigned the AcrPull role on the Azure Container Registry, enabling the Web App to pull the container image without storing credentials.
  10. Azure App Service Plan: The underlying compute tier that hosts the web application.
  11. Azure Web App: Runs the Python Flask application from the custom container image stored in the Azure Container Registry.

Prerequisites

Deployment

Set up the Azure emulator using the LocalStack for Azure Docker image. Before starting, ensure you have a valid LOCALSTACK_AUTH_TOKEN to access the Azure emulator. Refer to the Auth Token guide to obtain your Auth Token and set it in the LOCALSTACK_AUTH_TOKEN environment variable. The Azure Docker image is available on the LocalStack Docker Hub. To pull the image, execute:

docker pull localstack/localstack-azure-alpha

Start the LocalStack Azure emulator by running:

# Set the authentication token
export LOCALSTACK_AUTH_TOKEN=<your_auth_token>

# Start the LocalStack Azure emulator
IMAGE_NAME=localstack/localstack-azure-alpha localstack start -d
localstack wait -t 60

# Route all Azure CLI calls to the LocalStack Azure emulator
azlocal start-interception

Deploy the application to LocalStack for Azure using one of these methods:

All deployment methods have been fully tested against Azure and the LocalStack for Azure local emulator.

Note
When you deploy the application to LocalStack for Azure for the first time, the initialization process involves downloading and building Docker images. This is a one-time operation—subsequent deployments will be significantly faster. Depending on your internet connection and system resources, this initial setup may take several minutes.

Test

You can use the call-web-app.sh Bash script below to call the web app. The script calls the web app via the default hostname <web-app-name>.azurewebsites.azure.localhost.localstack.cloud:4566.

References