Introduction
Modern applications need to be scalable, reliable, and easy to deploy. Traditionally, developers deployed ASP.NET Core applications to virtual machines or managed web hosting platforms. While these approaches still work, containerization has become the preferred deployment method for many organizations.
Containers package an application along with all its dependencies, ensuring consistent behavior across development, testing, and production environments.
Microsoft Azure offers Azure Container Apps, a fully managed service that allows developers to run containerized applications without managing servers, Kubernetes clusters, or complex infrastructure.
In this tutorial, you'll learn how to deploy an ASP.NET Core application to Azure Container Apps step by step. We'll cover everything from creating the application to deploying it in Azure and accessing it through a public URL.
What Is Azure Container Apps?
Azure Container Apps is a serverless container hosting platform designed for modern cloud-native applications.
It allows developers to run containers without worrying about:
Virtual machines
Kubernetes management
Infrastructure maintenance
Operating system updates
Cluster scaling
Azure automatically handles:
Scaling
Load balancing
Infrastructure management
Networking
Monitoring
Think of Azure Container Apps as a middle ground between Azure App Service and Kubernetes.
You get the flexibility of containers without the complexity of managing Kubernetes clusters.
Why Use Azure Container Apps?
Many organizations choose Azure Container Apps because it offers:
Automatic scaling
Pay-for-usage pricing
Simplified deployments
Container support
Microservices-friendly architecture
Built-in HTTPS
Easy integration with Azure services
Real-World Example
Imagine you're building an e-commerce website.
During normal hours, your application receives 100 requests per minute.
During a festive sale, traffic suddenly increases to 10,000 requests per minute.
Azure Container Apps can automatically scale your application based on demand and scale back down when traffic decreases.
This helps reduce infrastructure costs while maintaining performance.
Prerequisites
Before starting, ensure you have:
Azure Subscription
.NET 8 SDK (or latest version)
Docker Desktop
Azure CLI
Visual Studio 2022 or VS Code
You can verify installations using:
dotnet --version
docker --version
az --version
Step 1: Create an ASP.NET Core Web API
Create a new ASP.NET Core API project.
dotnet new webapi -n ContainerAppDemo
Navigate to the project directory.
cd ContainerAppDemo
Run the application locally.
dotnet run
Open the browser and verify the API works.
Example URL:
https://localhost:5001/weatherforecast
If the API responds successfully, proceed to containerization.
Step 2: Create a Dockerfile
A Dockerfile defines how the application will be packaged into a container.
Create a file named:
Dockerfile
Add the following content:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "ContainerAppDemo.dll"]
This Dockerfile:
Restores dependencies
Builds the application
Publishes optimized files
Creates the final runtime image
Step 3: Build the Docker Image
Build the container image.
docker build -t containerappdemo .
Docker creates an image containing your application and runtime.
Verify the image.
docker images
Expected output:
REPOSITORY TAG IMAGE ID
containerappdemo latest xxxxxxxx
Step 4: Run the Container Locally
Test the container before deploying.
docker run -p 8080:8080 containerappdemo
Open:
http://localhost:8080/weatherforecast
If the API responds correctly, your container is ready for deployment.
Step 5: Create an Azure Resource Group
Azure resources are organized using Resource Groups.
Login to Azure.
az login
Create a resource group.
az group create \
--name ContainerAppRG \
--location eastus
Resource groups simplify management and cleanup of cloud resources.
Step 6: Create Azure Container Registry
Azure Container Registry (ACR) stores container images.
Create a registry.
az acr create \
--resource-group ContainerAppRG \
--name MyContainerRegistry123 \
--sku Basic
Login to the registry.
az acr login \
--name MyContainerRegistry123
Step 7: Tag the Docker Image
Docker images must be tagged before pushing to Azure.
docker tag containerappdemo \
mycontainerregistry123.azurecr.io/containerappdemo:v1
This associates your local image with Azure Container Registry.
Step 8: Push the Image to Azure Container Registry
Upload the image.
docker push \
mycontainerregistry123.azurecr.io/containerappdemo:v1
Azure now stores your application image.
You can verify this in the Azure Portal.
Step 9: Create a Container Apps Environment
Azure Container Apps require an environment.
Create one.
az containerapp env create \
--name ContainerEnvironment \
--resource-group ContainerAppRG \
--location eastus

Join the conversation! Your thoughts help the community grow.