Dockerfile for .NET 5 web application
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.
🚀 Turbocharge Your Infrastructure with Our Terraform Template Kits! 🚀
🌟 Slash deployment time and costs! Discover the ultimate solution for efficient, cost-effective cloud infrastructure. Perfect for DevOps enthusiasts looking for a reliable, scalable setup. Click here to revolutionize your workflow!
Learn More about Starter Terraform Kits for AKS,EKS and GKE
No comments are allowed for this post