Merge pull request 'Refactored dockerfile' (#10) from test into main
Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
25
Dockerfile
25
Dockerfile
@@ -2,21 +2,34 @@
|
|||||||
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 the solution and all project files to restore dependencies first (better caching)
|
# 1. Copy the .sln and .csproj files first to restore dependencies
|
||||||
|
# This makes builds faster by caching the 'restore' layer
|
||||||
|
COPY ["SampleApi/SampleApi.csproj", "SampleApi/"]
|
||||||
|
RUN dotnet restore "SampleApi/SampleApi.csproj"
|
||||||
|
|
||||||
|
# 2. Copy the rest of the code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Run publish.
|
# 3. Publish to a FLAT directory
|
||||||
# We use --no-self-contained to keep it small since the runtime image has the shared framework.
|
# We use -o /app/publish and ensure no extra subfolders are created
|
||||||
RUN dotnet publish "SampleApi/SampleApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
RUN dotnet publish "SampleApi/SampleApi.csproj" \
|
||||||
|
-c Release \
|
||||||
|
-o /app/publish \
|
||||||
|
--no-restore \
|
||||||
|
/p:UseAppHost=false
|
||||||
|
|
||||||
# STAGE 2: Runtime
|
# STAGE 2: Runtime
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the contents of the publish folder directly into /app
|
# Copy the contents directly
|
||||||
COPY --from=build /app/publish .
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
# Pro-tip: Ensure the port matches your docker-compose
|
# DEBUG: This will print the contents of /app during the build.
|
||||||
|
# If SampleApi.dll isn't in this list, the build will stop here.
|
||||||
|
RUN ls -la /app
|
||||||
|
|
||||||
|
# Set the environment to listen on the port you mapped in Compose
|
||||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||||
|
|
||||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||||
Reference in New Issue
Block a user