Skip to content
AI-200 Learn

Setup and local run

Run the Quote API locally with uvicorn or Docker Compose, then deploy it to ACR and Azure Container Apps with one script.

What this covers

This page gets the Quote API running on your machine, first as plain Python and then as a container, and then deploys it to Azure with a single script. Running locally first separates "my code is broken" from "my Azure configuration is broken". If the container works locally on port 8000 but fails in Azure, the problem is ports, registry auth or environment configuration, not the app.

Exam weight: Develop containerized solutions on Azure (20–25%)

Skills measured

  • "Build and run images by using Azure Container Registry Tasks"
  • "Build, store, version, and manage container images by using Azure Container Registry"
  • "Deploy applications to Azure Container Apps, including environment configuration and revision management"

Key concepts

Prerequisites

  • Python 3.12+
  • Azure CLI with the containerapp extension
  • Docker (optional, because ACR can build in the cloud)

Three ways to run

ModeCommandUse it for
Local Pythonuvicorn app.main:app --reload --port 8000Fast code iteration
Local containerdocker compose up --buildProve the image and port work
Azuredeploy.sh / deploy.ps1Resource group, ACR, cloud build, Container Apps

Why Docker is optional

The deploy script uses az acr build, an ACR quick task. The CLI uploads the source folder and ACR builds the image on its own agents and pushes it. Your laptop never runs docker build, which suits locked-down or ARM machines.

Naming rules

ACR names must be globally unique, 5–50 alphanumeric characters, with no hyphens. If quoteapiacr is taken, the script fails at az acr create. Override it with ACR_NAME.

How it works

Diagram source: flowchart LR Dev[Developer] --> Py[uvicorn :8000] Dev --> DC[docker compose :8000] Dev --> Script[deploy.sh / deploy.ps1] Script --> RG[az group create] Script --> ACR[az acr create + az acr build] Script --> ACA[az containerapp create] ACA --> URL[https FQDN]

The script creates the resource group, the ACR, builds the image and deploys to Container Apps.

Hands-on

Azure portal

  1. After the script finishes, open Container Apps and select quote-api.
  2. Copy the Application Url and append /docs to open Swagger UI.
  3. In the registry, open Services > Tasks > Runs to see the quick-task build that az acr build created.

Azure CLI

Run locally with Python:

Azure CLI / Bash
cd quote-api
python -m venv .venv

Activate on Windows:

PowerShell
.venv\Scripts\Activate.ps1

Activate on Linux/macOS:

Azure CLI / Bash
source .venv/bin/activate
Azure CLI / Bash
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

Open http://localhost:8000/docs.

Run with Docker:

Azure CLI / Bash
cd quote-api
docker compose up --build

Deploy to Azure on Windows:

PowerShell
cd quote-api
.\deploy.ps1

Deploy on Linux/macOS:

Azure CLI / Bash
cd quote-api
chmod +x deploy.sh
./deploy.sh

Set a unique ACR name if needed:

Azure CLI / Bash
ACR_NAME=myuniqueacr123 ./deploy.sh

Check that the name is free before deploying:

Azure CLI / Bash
az acr check-name --name myuniqueacr123 --query nameAvailable

Python

Local smoke test while uvicorn is running:

Python
import requests

r = requests.get("http://localhost:8000/health", timeout=5)
print(r.status_code, r.json())

Exam traps

ProblemFix
No Docker on the build machineaz acr build (quick task)
az acr create says the name is takenPick a globally unique name (az acr check-name)
Works locally, unreachable in AzureBind 0.0.0.0 and match --target-port 8000
az containerapp missing parametersaz extension add --name containerapp --upgrade

Quick review

  • Prerequisites: Python 3.12+, Azure CLI, Docker optional.
  • Local run: uvicorn app.main:app --reload --port 8000, then /docs.
  • Container run: docker compose up --build.
  • Azure deploy: deploy.sh or deploy.ps1 creates the RG, ACR, image and container app.
  • ACR names must be globally unique. Override with ACR_NAME.
  • az acr build makes a local Docker install unnecessary.

Practice

Official references