Refactored docker file
This commit is contained in:
25
Dockerfile
25
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
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
WORKDIR /src
|
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
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
WORKDIR /app
|
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 .
|
COPY --from=build /app/publish .
|
||||||
# The DLL is now in the root of /app, so no folder prefix is needed
|
|
||||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
# 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