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
containerappextension - Docker (optional, because ACR can build in the cloud)
Three ways to run
| Mode | Command | Use it for |
|---|---|---|
| Local Python | uvicorn app.main:app --reload --port 8000 | Fast code iteration |
| Local container | docker compose up --build | Prove the image and port work |
| Azure | deploy.sh / deploy.ps1 | Resource 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
The script creates the resource group, the ACR, builds the image and deploys to Container Apps.
Hands-on
Azure portal
- After the script finishes, open Container Apps and select
quote-api. - Copy the Application Url and append
/docsto open Swagger UI. - In the registry, open Services > Tasks > Runs to see the quick-task build that
az acr buildcreated.
Azure CLI
Run locally with Python:
cd quote-api
python -m venv .venvActivate on Windows:
.venv\Scripts\Activate.ps1Activate on Linux/macOS:
source .venv/bin/activatepip install -r requirements.txt
uvicorn app.main:app --reload --port 8000Open http://localhost:8000/docs.
Run with Docker:
cd quote-api
docker compose up --buildDeploy to Azure on Windows:
cd quote-api
.\deploy.ps1Deploy on Linux/macOS:
cd quote-api
chmod +x deploy.sh
./deploy.shSet a unique ACR name if needed:
ACR_NAME=myuniqueacr123 ./deploy.shCheck that the name is free before deploying:
az acr check-name --name myuniqueacr123 --query nameAvailablePython
Local smoke test while uvicorn is running:
import requests
r = requests.get("http://localhost:8000/health", timeout=5)
print(r.status_code, r.json())Exam traps
| Problem | Fix |
|---|---|
| No Docker on the build machine | az acr build (quick task) |
az acr create says the name is taken | Pick a globally unique name (az acr check-name) |
| Works locally, unreachable in Azure | Bind 0.0.0.0 and match --target-port 8000 |
az containerapp missing parameters | az 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.shordeploy.ps1creates the RG, ACR, image and container app. - ACR names must be globally unique. Override with
ACR_NAME. az acr buildmakes a local Docker install unnecessary.
Practice
- Practice: ACR Tasks questions
- Practice: Azure Container Registry questions
- Practice: Container Apps deployment questions