Skip to content

Latest commit

 

History

History
120 lines (74 loc) · 7.36 KB

tutorial-containerize-deploy-python-web-app-azure-01.md

File metadata and controls

120 lines (74 loc) · 7.36 KB
title description ms.topic ms.date ms.custom
Deploy a containerized Python web app on Azure with MongoDB
An overview of how to create and deploy a containerized Python web app (Django or Flask) on Azure App Service with MongoDB.
conceptual
03/17/2025
devx-track-python

Overview: Containerized Python web app on Azure with MongoDB

This tutorial series shows you how to containerize a Python web app and then either run it locally or deploy it to Azure App Service. App Service Web App for Containers allows you to focus on building your containers without worrying about managing and maintaining an underlying container orchestrator. When you are building web apps, Azure App Service is a good option for taking your first steps with containers. This container web app can use either a local MongoDB instance or MongoDB for Azure Cosmos DB to store data. For more information about using containers in Azure, see Comparing Azure container options.

In this tutorial you:

After completing the articles in this tutorial series, you'll have the basis for Continuous Integration (CI) and Continuous Deployment (CD) of a Python web app to Azure.

Service overview

The service diagram supporting this tutorial shows two environments: developer environment and Azure environment. It highlights the key Azure services used in the development process.

:::image type="content" source="./media/tutorial-container-web-app/containerization-of-python-apps-overview.png" alt-text="A screenshot of the services used in the Tutorial - Containerized Python App on Azure." lightbox="./media/tutorial-container-web-app/containerization-of-python-apps-overview.png":::

Developer environment

The components supporting the developer environment in this tutorial include:

  • Local Development System: A personal computer used for coding, building, and testing the Docker container.

  • Docker Containerization: Docker is employed to package the app and its dependencies into a portable container.

  • Development Tools: Includes a code editor and other necessary tools for software development.

  • Local MongoDB Instance: A local MongoDB database utilized for data storage during development.

  • MongoDB Connection: Access to the local MongoDB database provided through a connection string.

Azure environment

The components supporting the Azure environment in this tutorial include:

  • Azure App Service

    • In Azure App Service, Web App for Containers uses the Docker container technology to provide container hosting of both built-in images and custom images using Docker.
    • Web App for Containers uses a webhook in the Azure Container Registry (ACR) to get notified of new images. When a new image is pushed to the registry, the webhook notification triggers App Service to pull the update and restart the app.
  • Azure Container Registry

    • Azure Container Registry allows you to store and manage Docker images and their components in Azure. It provides a registry located near your deployments in Azure that gives you the ability to control access using your Microsoft Entra groups and permissions.

    • In this tutorial, Azure Container Registry is the registry source, but you can also use Docker Hub or a private registry with minor modifications.

  • Azure Cosmos DB for MongoDB

    • The Azure Cosmos DB for MongoDB is a NoSQL database used in this tutorial for data storage.

    • The containerized application connects to and accesses the Azure Cosmos DB resource using a connection string, which is stored as an environment variable and provided to the app.

Authentication

In this tutorial, you build a Docker image, either locally or in Azure, and then deploy it to Azure App Service. The App Service pulls the container image from an Azure Container Registry repository.

To securely pull images from the repository, App Service utilizes a system-assigned managed identity. This managed identity grants the web app permissions to interact with other Azure resources, eliminating the need for explicit credentials. For this tutorial, the managed identity is configured during setup of App Service to use a registry container image.

The tutorial sample web app uses MongoDB to store data. The sample code connects to Azure Cosmos DB via a connection string.

Prerequisites

To complete this tutorial, you need:

Sample app

The end result of this tutorial is a restaurant review app, deployed and running in Azure, that looks like the following screenshot.

:::image type="content" source="./media/tutorial-container-web-app/containerization-of-python-web-app-sample-app-screenshot.png" alt-text="A screenshot of the sample app created from the Python containerized web app used in the Tutorial - Containerized Python App on Azure." lightbox="./media/tutorial-container-web-app/containerization-of-python-web-app-sample-app-screenshot.png":::

In this tutorial, you build a Python restaurant review app that utilizes MongoDB for data storage. For an example app using PostgreSQL, see Create and deploy a Flask web app to Azure with a managed identity.

Next step

[!div class="nextstepaction"] Build and test locally