Merge pull request 'Refactored docker file' (#9) from test into main
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
23
Dockerfile
23
Dockerfile
@@ -1,15 +1,22 @@
|
||||
# STAGE 1: Build (Uses the heavy SDK)
|
||||
# STAGE 1: Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
# Copy everything from the solution folder
|
||||
COPY . .
|
||||
# Publish specifically the project from its subfolder
|
||||
RUN [dotnet publish](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish) "SampleApi/SampleApi.csproj" -c Release -o /app/publish
|
||||
|
||||
# STAGE 2: Runtime (Uses the slim ASP.NET image)
|
||||
# Copy the solution and all project files to restore dependencies first (better caching)
|
||||
COPY . .
|
||||
|
||||
# Run publish.
|
||||
# We use --no-self-contained to keep it small since the runtime image has the shared framework.
|
||||
RUN dotnet publish "SampleApi/SampleApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# STAGE 2: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
WORKDIR /app
|
||||
# Copy ONLY the compiled binaries from the build stage
|
||||
|
||||
# Copy the contents of the publish folder directly into /app
|
||||
COPY --from=build /app/publish .
|
||||
# The DLL is now in the root of /app, so no folder prefix is needed
|
||||
|
||||
# Pro-tip: Ensure the port matches your docker-compose
|
||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||
|
||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||
Reference in New Issue
Block a user