Created
March 13, 2025 19:31
-
-
Save jincod/13b4eb0dfe46b4286b111ec7ef62e62c to your computer and use it in GitHub Desktop.
Dockerfile for .NET projects. Supports caching nuget packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS builder | |
WORKDIR /source | |
# COPY ./libs/ ./libs/ | |
COPY ./*.sln ./nuget.config /*.props /*.targets ./ | |
# Copy the main source project files | |
COPY src/*/*.csproj ./ | |
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done | |
RUN dotnet restore -r linux-musl-x64 | |
# Copy across the rest of the source files | |
COPY ./src ./src | |
RUN dotnet publish ./src/Web/Web.csproj -c Release -r linux-musl-x64 -o /app/out --no-restore --self-contained | |
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine | |
WORKDIR /app | |
COPY --from=builder /app/out . | |
USER $APP_UID | |
ENTRYPOINT ["./Web"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment