37 lines
1.5 KiB
Docker
37 lines
1.5 KiB
Docker
# Phase 1: Die Build-Phase
|
|
# Wir verwenden das offizielle .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.
|
|
# Docker ist schlau: Wenn sich diese Dateien nicht ändern, verwendet es den Cache und der 'restore'-Schritt wird übersprungen.
|
|
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 für die gesamte Solution herunter.
|
|
RUN dotnet restore "ShopSolution.sln"
|
|
|
|
# Kopiere den gesamten restlichen Quellcode.
|
|
COPY . .
|
|
|
|
# Wechsle in das Verzeichnis des API-Projekts.
|
|
WORKDIR "/src/Webshop.Api"
|
|
# Baue und publiziere die Anwendung in einer Release-Konfiguration.
|
|
# Das Ergebnis wird in den Ordner /app/publish verschoben.
|
|
RUN dotnet publish "Webshop.Api.csproj" -c Release -o /app/publish --no-restore
|
|
|
|
# ---
|
|
|
|
# Phase 2: Die finale Runtime-Phase
|
|
# Wir verwenden das deutlich kleinere ASP.NET Core Runtime-Image, da wir den Code nicht mehr kompilieren müssen.
|
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
|
|
WORKDIR /app
|
|
|
|
# Kopiere nur die publizierte Anwendung aus der Build-Phase.
|
|
COPY --from=build /app/publish .
|
|
|
|
# Definiere den Befehl, der ausgeführt wird, wenn der Container startet.
|
|
ENTRYPOINT ["dotnet", "Webshop.Api.dll"] |