Deploying an ASP.NET Core application using Docker and Azure Web App for Containers is a modern and scalable approach for hosting cloud-native applications. This deployment strategy combines containerization with fully managed Azure infrastructure, enabling portability, consistency across environments, and simplified DevOps workflows. By packaging your application inside a Docker container and deploying it to Azure Web App for Containers, you gain flexibility, isolation, and production-ready scalability without managing virtual machines.
This article provides a complete practical guide, including architecture explanation, Dockerfile configuration, container registry setup, Azure deployment steps, real-world scenarios, advantages, disadvantages, and production best practices.
What Does It Mean to Deploy Using Docker and Azure Web App for Containers?
In traditional deployment, applications are published directly to a server. In containerized deployment:
The ASP.NET Core application is packaged into a Docker image.
The image contains application code, runtime, dependencies, and configuration.
The image is pushed to a container registry.
Azure Web App pulls and runs the container.
In simple terms, instead of deploying files, you deploy a portable runtime environment.
Why Use Docker with ASP.NET Core?
Docker provides:
Environment consistency (works the same in development and production)
Isolation from host system
Simplified CI/CD integration
Easier scaling and rollback
Microservices compatibility
For modern DevOps pipelines, containerization is a best practice.
Real-World Analogy
Think of Docker like shipping goods in standardized containers. Regardless of what is inside, ports and ships handle containers uniformly. Azure Web App acts like a managed port that runs your container without worrying about the internal contents.
High-Level Architecture Flow
Developer → Build Docker Image → Push to Azure Container Registry → Azure Web App Pulls Image → Container Runs → Public Endpoint Available
This ensures consistent deployment across environments.
Step 1: Create ASP.NET Core Application
Create a Web API project:
dotnet new webapi -n MyApp
cd MyApp
Step 2: Create Dockerfile
Inside project root, create a file named Dockerfile:
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o /publish
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /publish .
EXPOSE 8080
ENTRYPOINT ["dotnet", "MyApp.dll"]
This uses multi-stage build to reduce final image size.
Step 3: Build Docker Image Locally
docker build -t myapp:latest .
Test locally:
docker run -p 8080:8080 myapp
Access via:
http://localhost:8080
Step 4: Push Image to Azure Container Registry (ACR)
Create ACR:
az acr create --resource-group MyResourceGroup --name MyContainerRegistry --sku Basic
Login to ACR:
az acr login --name MyContainerRegistry
Tag image:
docker tag myapp:latest mycontainerregistry.azurecr.io/myapp:latest
Push image:
docker push mycontainerregistry.azurecr.io/myapp:latest
Step 5: Create Azure Web App for Containers
Create App Service Plan:
az appservice plan create --name MyAppServicePlan --resource-group MyResourceGroup --is-linux --sku B1
Create Web App:
az webapp create \
--resource-group MyResourceGroup \
--plan MyAppServicePlan \
--name MyDockerWebApp \
--deployment-container-image-name mycontainerregistry.azurecr.io/myapp:latest
Configure container registry credentials:
az webapp config container set \
--name MyDockerWebApp \
--resource-group MyResourceGroup \
--docker-custom-image-name mycontainerregistry.azurecr.io/myapp:latest \
--docker-registry-server-url https://mycontainerregistry.azurecr.io
Azure will pull the image and run the container.
Step 6: Configure Environment Variables
In Azure Portal or CLI:
az webapp config appsettings set \
--name MyDockerWebApp \
--resource-group MyResourceGroup \
--settings ASPNETCORE_ENVIRONMENT=Production
Environment variables should not be hardcoded inside Docker image.
Real Business Scenario: SaaS Application
Consider a SaaS platform serving thousands of users:
Application is containerized.
CI/CD pipeline builds image on each commit.
Image pushed to ACR.
Azure Web App automatically pulls new image.
Auto-scaling handles traffic spikes.
If a deployment fails, rollback is as simple as redeploying previous image tag.
Join the conversation! Your thoughts help the community grow.