From 4b71b16b782a2d9215980d04da034716c46df18b Mon Sep 17 00:00:00 2001 From: khwezi Date: Tue, 3 Mar 2026 17:26:54 +0200 Subject: [PATCH] Refactored docker file --- Dockerfile | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28e6c17..67d477b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,22 @@ -# STAGE 1: Build (Uses the heavy SDK) +# STAGE 1: Build FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src -# Copy everything from the solution folder -COPY . . -# Publish specifically the project from its subfolder -RUN [dotnet publish](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish) "SampleApi/SampleApi.csproj" -c Release -o /app/publish -# STAGE 2: Runtime (Uses the slim ASP.NET image) +# Copy the solution and all project files to restore dependencies first (better caching) +COPY . . + +# Run publish. +# We use --no-self-contained to keep it small since the runtime image has the shared framework. +RUN dotnet publish "SampleApi/SampleApi.csproj" -c Release -o /app/publish /p:UseAppHost=false + +# STAGE 2: Runtime FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app -# Copy ONLY the compiled binaries from the build stage + +# Copy the contents of the publish folder directly into /app COPY --from=build /app/publish . -# The DLL is now in the root of /app, so no folder prefix is needed -ENTRYPOINT ["dotnet", "SampleApi.dll"] + +# Pro-tip: Ensure the port matches your docker-compose +ENV ASPNETCORE_HTTP_PORTS=8081 + +ENTRYPOINT ["dotnet", "SampleApi.dll"] \ No newline at end of file -- 2.47.3