Files
simpleidp/Dockerfile
Marek Lesko 4ac1f94249 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.
2025-09-04 14:09:52 +02:00

35 lines
914 B
Docker

# =========================
# 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"]