Dockerfile
This commit is contained in:
@@ -1,25 +1,37 @@
|
|||||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
# Phase 1: Die Build-Phase
|
||||||
|
# Wir verwenden das offizielle .NET 8 SDK-Image, das alle Werkzeuge zum Bauen enth<74>lt.
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
|
||||||
USER app
|
|
||||||
WORKDIR /app
|
|
||||||
EXPOSE 8080
|
|
||||||
EXPOSE 8081
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
|
# Kopiere zuerst die Projekt- und Solution-Dateien.
|
||||||
|
# Docker ist schlau: Wenn sich diese Dateien nicht <20>ndern, verwendet es den Cache und der 'restore'-Schritt wird <20>bersprungen.
|
||||||
|
COPY ["ShopSolution.sln", "."]
|
||||||
COPY ["Webshop.Api/Webshop.Api.csproj", "Webshop.Api/"]
|
COPY ["Webshop.Api/Webshop.Api.csproj", "Webshop.Api/"]
|
||||||
RUN dotnet restore "./Webshop.Api/Webshop.Api.csproj"
|
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<62>ngigkeiten f<>r die gesamte Solution herunter.
|
||||||
|
RUN dotnet restore "ShopSolution.sln"
|
||||||
|
|
||||||
|
# Kopiere den gesamten restlichen Quellcode.
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Wechsle in das Verzeichnis des API-Projekts.
|
||||||
WORKDIR "/src/Webshop.Api"
|
WORKDIR "/src/Webshop.Api"
|
||||||
RUN dotnet build "./Webshop.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
# 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
|
||||||
|
|
||||||
FROM build AS publish
|
# ---
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
RUN dotnet publish "./Webshop.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
|
||||||
|
|
||||||
FROM base AS final
|
# 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
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
|
# Kopiere nur die publizierte Anwendung aus der Build-Phase.
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
|
# Definiere den Befehl, der ausgef<65>hrt wird, wenn der Container startet.
|
||||||
ENTRYPOINT ["dotnet", "Webshop.Api.dll"]
|
ENTRYPOINT ["dotnet", "Webshop.Api.dll"]
|
||||||
Reference in New Issue
Block a user