Alex's Coding Blog
  • home
  • about
  • projects
  • contact

Blog

Dockerfile for .NET 5 web application

  • January 13, 2021 March 16, 2025
  • by Alexander

Recently, I upgraded a few of my projects to .NET 5.0. Most of project shipped as docker containers, the upgrade requires making some changed to docker files. Converting from .NET Core 2.2/3.1 to .NET 5 is streight forward. Here are some notes from the process:

Dockerfile files are cool when they are working. In order to make them work without additional effort is better to keep similar folder structure between the projects.

I use the following structure for my projects:

/src
/tests
/Dockerfile

.NET application docker file example

# pick image including .net sdk for compilation
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
# change directiry
WORKDIR /app
# copy 
COPY src/ ./
# if special config is used
COPY nuget.config ./
# restore
RUN dotnet restore "./Api.csproj" --configfile "./nuget.config"
# publish
RUN dotnet publish "./Api.csproj" -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
COPY --from=build-env /app/out .
# expose port
EXPOSE 6032
# set .net app to expose a port
ENV ASPNETCORE_URLS http://*:6032
# run
ENTRYPOINT ["dotnet", "Api.dll"]

If console application is deployed mcr.microsoft.com/dotnet/runtime:5.0 should be used as a build image.

.NET Core DevOps How-to

🚀 Turbocharge Your Kubernetes Cluster with my Terraform Kits! 🚀

🌟 Slash deployment time and costs! Discover the ultimate solution for efficient, cost-effective Kubernetes Terraform Kits. Perfect for DevOps enthusiasts looking for a reliable, scalable setup.

Learn More about Terraform Kits for AKS,EKS and GKE

Alexander Lvovich

Solution Architect & Software Developer | Automating & Scaling Infrastructure

💡 Working with Kubernetes, Istio, and DevOps. Got questions? Feel free to reach out!

Share on:

No comments are allowed for this post

Recent Posts

  • Securing Web Services Against Unwanted Traffic with NGINX
  • Optimizing API by Offloading Responsibilities to an API Gateway
  • How to Clean Up Local Branches of Remote Merged Branches
  • Resolving Namespace Overriding in Argo CD with Kustomize
  • Connecting to Gitlab's private Nuget registry
  • Why Istio?

Categories

  • Azure
  • Architecture
  • .NET Core
  • Certification
  • DevOps
  • How-to
  • Azure Functions
  • Serverless
  • Cosmos DB
  • Security
  • Thoughts
  • Kubernetes
  • Istio
© Copyright 2025, Alexander Lvovich. Theme by Colorlib
I use cookies and similar technologies on our website to enhance your browsing experience and analyze website traffic. By clicking "Accept," you consent with my Privacy Policy to the use of these technologies.
Accept