Deploying an ASP.NET Core App
Learn how to publish and deploy an ASP.NET Core application, including Docker containerization.
Publishing Your App
`dotnet publish` compiles an optimized, deployment-ready build of your application.
dotnet publish -c Release -o ./publishThis produces a self-contained folder you can copy to a server and run with `dotnet YourApp.dll`.
Containerizing with Docker
Docker packages your app with everything it needs to run consistently across any environment — a standard approach for modern ASP.NET Core deployment.
Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS baseWORKDIR /appEXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS buildWORKDIR /srcCOPY . .RUN dotnet publish -c Release -o /app/publish
FROM base AS finalWORKDIR /appCOPY --from=build /app/publish .ENTRYPOINT ["dotnet", "TaskApi.dll"]docker build -t taskapi .docker run -p 8080:8080 taskapiHosting Options
| Platform | Best For |
|---|---|
| Azure App Service | Fully managed, deep integration with the .NET ecosystem |
| AWS / Google Cloud | Cloud-agnostic, containerized deployments |
| A VPS with Docker | Full control, cost-effective for smaller apps |
| Render / Railway | Simple, developer-friendly platforms with free tiers for learning |
Production Checklist
- Set ASPNETCORE_ENVIRONMENT to Production.
- Store secrets in environment variables or a secrets manager, never in source control.
- Enable HTTPS and HSTS.
- Run pending EF Core migrations against the production database.
- Set up logging and monitoring for errors in production.
FAQs
No — you can deploy the published output directly to many hosts. Docker is popular because it guarantees consistency between your local environment and production.
Summary
- dotnet publish produces an optimized, deployable build.
- Docker packages your app for consistent deployment anywhere.
- Always separate environment-specific config and secrets from source control before going to production.