Files
Rbm.FamStack/Dockerfile
T
2026-10-09 18:25:11 +02:00

49 lines
2.0 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# syntax=docker/dockerfile:1
# Gemeinsames Dockerfile für Api, Web und MigrationService.
# docker build --build-arg PROJECT=FamilyPlanner.Api -t familyplanner-api .
# Alternativ ohne Docker-Build: dotnet publish src/<Projekt> -c Release /t:PublishContainer
ARG DOTNET_VERSION=10.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
ARG PROJECT
WORKDIR /src
# Zuerst nur Projektdateien kopieren, damit der Restore-Layer gecacht wird.
COPY global.json Directory.Build.props Directory.Packages.props .editorconfig ./
COPY src/FamilyPlanner.Domain/*.csproj src/FamilyPlanner.Domain/
COPY src/FamilyPlanner.Shared/*.csproj src/FamilyPlanner.Shared/
COPY src/FamilyPlanner.Infrastructure/*.csproj src/FamilyPlanner.Infrastructure/
COPY src/FamilyPlanner.ServiceDefaults/*.csproj src/FamilyPlanner.ServiceDefaults/
COPY src/FamilyPlanner.Api/*.csproj src/FamilyPlanner.Api/
COPY src/FamilyPlanner.MigrationService/*.csproj src/FamilyPlanner.MigrationService/
COPY src/FamilyPlanner.Web/*.csproj src/FamilyPlanner.Web/
COPY src/FamilyPlanner.Web.Client/*.csproj src/FamilyPlanner.Web.Client/
RUN dotnet restore "src/${PROJECT}/${PROJECT}.csproj"
COPY src/ src/
# Kein --no-restore: das SDK referenziert Microsoft.AspNetCore.App.Internal.Assets (blazor.web.js) erst,
# wenn Razor-Komponenten im Projekt liegen – das ist beim Restore-Layer oben noch nicht der Fall.
RUN dotnet publish "src/${PROJECT}/${PROJECT}.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION} AS final
ARG PROJECT
# curl nur für Docker-Health-Checks.
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/publish .
ENV ASPNETCORE_HTTP_PORTS=8080 \
DOTNET_RUNNING_IN_CONTAINER=true \
APP_DLL=${PROJECT}.dll
EXPOSE 8080
# Non-Root: der Benutzer "app" (UID 1654) ist in den Microsoft-Images vorhanden.
USER $APP_UID
ENTRYPOINT ["sh", "-c", "exec dotnet \"$APP_DLL\""]