From 4ac1f942492da50574d70be8936587f793819815 Mon Sep 17 00:00:00 2001 From: Marek Lesko Date: Thu, 4 Sep 2025 14:09:52 +0200 Subject: [PATCH] Update Dockerfile for multi-stage .NET build process Implemented a multi-stage build in the Dockerfile, adding a build stage with the .NET SDK for restoring and publishing the application. Introduced a runtime stage using the ASP.NET image, created a non-root user for enhanced security, and set necessary environment variables. The published output is now copied from the build stage, and the entry point is configured to launch the application. --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b7cc026 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# ========================= +# Build stage +# ========================= +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src + +# Copy everything (simple + reliable for single-project Razor Pages apps) +COPY . . + +# Restore & publish (self-contained trimming can be added later if desired) +RUN dotnet restore +RUN dotnet publish -c $BUILD_CONFIGURATION -o /app/publish --no-restore + +# ========================= +# Runtime stage +# ========================= +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final +WORKDIR /app + +# (Optional) Create non-root user for better security +RUN useradd -m appuser +ENV ASPNETCORE_URLS=http://+:8080 \ + ASPNETCORE_ENVIRONMENT=Production \ + DOTNET_RUNNING_IN_CONTAINER=true +EXPOSE 8080 + +# Copy published output +COPY --from=build /app/publish ./ + +# Switch to non-root +USER appuser + +# Start the Razor Pages app +ENTRYPOINT ["dotnet", "SimpleIdp.dll"] \ No newline at end of file