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:
Azure automatically handles:
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:
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:
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:
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
This environment hosts one or more container applications.
Step 10: Deploy the Container App
Deploy your application.
az containerapp create \
--name mycontainerapp \
--resource-group ContainerAppRG \
--environment ContainerEnvironment \
--image mycontainerregistry123.azurecr.io/containerappdemo:v1 \
--target-port 8080 \
--ingress external \
--registry-server mycontainerregistry123.azurecr.io
Azure now:
Pulls the image
Creates a container
Configures networking
Enables public access
Deployment usually takes a few minutes.
Step 11: Access the Application
Retrieve the application URL.
az containerapp show \
--name mycontainerapp \
--resource-group ContainerAppRG \
--query properties.configuration.ingress.fqdn
Example output:
mycontainerapp.azurecontainerapps.io
Open:
https://mycontainerapp.azurecontainerapps.io/weatherforecast
Your ASP.NET Core application is now running in Azure.
Understanding Auto Scaling
One of the biggest advantages of Azure Container Apps is automatic scaling.
Azure can:
Traditional Deployment
Application
↓
Fixed Servers
↓
Pay Even When Idle
Azure Container Apps
Application
↓
Automatic Scaling
↓
Pay Based On Usage
This can significantly reduce cloud costs.
Updating the Application
Suppose you make code changes.
Build a new image.
docker build -t containerappdemo .
Tag a new version.
docker tag containerappdemo \
mycontainerregistry123.azurecr.io/containerappdemo:v2
Push the image.
docker push \
mycontainerregistry123.azurecr.io/containerappdemo:v2
Update the deployment.
az containerapp update \
--name mycontainerapp \
--resource-group ContainerAppRG \
--image mycontainerregistry123.azurecr.io/containerappdemo:v2
Azure creates a new revision and deploys the updated version.
Monitoring Container Apps
Azure provides built-in monitoring.
You can track:
CPU usage
Memory consumption
Request count
Application logs
Response times
Scaling events
Monitoring helps identify issues before they impact users.
Common Deployment Issues
Incorrect Port Configuration
If the application isn't reachable:
--target-port 8080
Ensure it matches the Docker container port.
Registry Authentication Problems
Verify Azure Container Registry login.
az acr login --name MyContainerRegistry123
Container Startup Failures
Check logs.
az containerapp logs show \
--name mycontainerapp \
--resource-group ContainerAppRG
Logs often reveal startup issues quickly.
Azure Container Apps vs Azure App Service
| Feature | Azure Container Apps | Azure App Service |
|---|
| Container Support | Excellent | Good |
| Scale to Zero | Yes | No |
| Microservices Support | Excellent | Limited |
| Kubernetes Features | Supported | Not Supported |
| Infrastructure Management | Fully Managed | Fully Managed |
| Cost Efficiency | High | Moderate |
Container Apps are generally preferred for containerized and microservices-based applications.
Best Practices
When deploying ASP.NET Core applications to Azure Container Apps:
Use multi-stage Docker builds.
Keep container images small.
Use environment variables for configuration.
Enable monitoring and logging.
Use Azure Key Vault for secrets.
Implement health checks.
Version container images properly.
Automate deployments using CI/CD pipelines.
These practices improve reliability and maintainability.
Advantages of Azure Container Apps
Benefits include:
No infrastructure management
Automatic scaling
Pay-as-you-go pricing
Fast deployments
Container-native architecture
Built-in HTTPS support
Easy integration with Azure services
Microservices-friendly design
Conclusion
Azure Container Apps provides one of the easiest ways to deploy containerized ASP.NET Core applications in the cloud. It eliminates the complexity of managing servers and Kubernetes clusters while offering powerful features such as automatic scaling, built-in networking, monitoring, and cost optimization.
By combining ASP.NET Core, Docker, and Azure Container Apps, developers can build scalable cloud-native applications that are easier to deploy, maintain, and operate. Whether you're building APIs, microservices, background jobs, or enterprise applications, Azure Container Apps offers a modern and efficient deployment platform that helps teams focus more on development and less on infrastructure management.