Compare commits

..

2 Commits

Author SHA1 Message Date
d30ee959ee Merge pull request 'Refactored docker file' (#9) from test into main
Reviewed-on: #9
2026-03-03 17:27:19 +02:00
4b71b16b78 Refactored docker file 2026-03-03 17:26:54 +02:00

View File

@@ -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"]