AI-200
Azure
Back to Deploy and operate containers on Azure App Service

Project: Example — Deploying a container to Azure Container Apps

Commands reference

Local

CommandDescription
uvicorn app.main:app --reload --port 8000Run API locally
docker compose up --buildRun with Docker Compose
docker build -t quote-api:local .Build image locally
python -m flake8 app/Lint code

Azure — login and resources

CommandDescription
az loginSign in to Azure
az account set -s "Subscription Name"Select subscription
az group create -n quote-api-rg -l eastusCreate resource group
az group delete -n quote-api-rg --yesDelete resource group

Azure — Container Registry

CommandDescription
az acr create -g quote-api-rg -n quoteapiacr --sku Basic --admin-enabled trueCreate ACR
az acr login -n quoteapiacrLog Docker into ACR
az acr build -r quoteapiacr -t quote-api:latest .Quick build and push
az acr build -r quoteapiacr -f acr-task.yaml .Multi-step build (lint + push)
az acr repository list -n quoteapiacr -o tableList repositories
az acr repository show-tags -n quoteapiacr --repository quote-apiList image tags

Azure — ACR Tasks

CommandDescription
az acr task create -n quote-api-build -r quoteapiacr -f acr-task.yaml --context .Create a task
az acr task run -n quote-api-build -r quoteapiacrRun task manually
az acr task list -r quoteapiacr -o tableList all tasks
az acr task logs -r quoteapiacr --run-id <id>View build logs
az acr task delete -n quote-api-build -r quoteapiacr --yesDelete a task

GitHub-triggered task

Azure CLI
az acr task create \
  -n quote-api-github-build \
  -r quoteapiacr \
  -f acr-task.yaml \
  --context https://github.com/YOUR-ORG/YOUR-REPO.git#main \
  --git-access-token YOUR_GITHUB_PAT \
  --commit-trigger-enabled true \
  --branch main

Scheduled task (nightly 2 AM UTC)

Azure CLI
az acr task create \
  -n quote-api-nightly \
  -r quoteapiacr \
  -f acr-task.yaml \
  --context . \
  --schedule "0 2 * * *"

Azure — Container Apps

CommandDescription
az containerapp env create -n quote-api-env -g quote-api-rg -l eastusCreate environment
az containerapp show -n quote-api -g quote-api-rg --query properties.configuration.ingress.fqdn -o tsvGet app URL
az containerapp update -n quote-api -g quote-api-rg --image quoteapiacr.azurecr.io/quote-api:latestUpdate image
az containerapp logs show -n quote-api -g quote-api-rgView app logs

API

MethodEndpointDescription
GET/Welcome message
GET/quotesList all quotes
GET/quotes/randomRandom quote
POST/quotesCreate quote
DELETE/quotes/{id}Delete quote
GET/healthHealth check
GET/docsSwagger UI

Repository

https://github.com/Suralmk/azure-contianers