# Phase 1: Die Build-Phase # Verwendet das .NET 8 SDK-Image, das alle Werkzeuge zum Bauen enthält. FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src # Kopiere zuerst die Projekt- und Solution-Dateien, um den Docker-Cache optimal zu nutzen. COPY ["ShopSolution.sln", "."] COPY ["Webshop.Api/Webshop.Api.csproj", "Webshop.Api/"] COPY ["Webshop.Application/Webshop.Application.csproj", "Webshop.Application/"] COPY ["Webshop.Domain/Webshop.Domain.csproj", "Webshop.Domain/"] COPY ["Webshop.Infrastructure/Webshop.Infrastructure.csproj", "Webshop.Infrastructure/"] # Lade alle NuGet-Abhängigkeiten herunter. RUN dotnet restore "ShopSolution.sln" # Kopiere den gesamten restlichen Quellcode. COPY . . # Publiziert die Anwendung in einer Release-Konfiguration. # `dotnet publish` kopiert automatisch alle notwendigen Dateien, einschließlich `wwwroot`. WORKDIR "/src/Webshop.Api" RUN dotnet publish "Webshop.Api.csproj" -c Release -o /app/publish --no-restore # --- # Phase 2: Die finale Runtime-Phase # Verwendet das kleinere ASP.NET Core Runtime-Image für eine geringere Größe. FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final WORKDIR /app # Kopiere nur die publizierte Anwendung aus der Build-Phase. # Der `publish`-Ordner enthält die DLLs, Abhängigkeiten und den `wwwroot`-Ordner. COPY --from=build /app/publish . # Definiere den Befehl, der ausgeführt wird, wenn der Container startet. ENTRYPOINT ["dotnet", "Webshop.Api.dll"]