Compare commits
2 Commits
d30ee959ee
...
57ba629d2d
| Author | SHA1 | Date | |
|---|---|---|---|
| 57ba629d2d | |||
| 0a0877dc4d |
25
Dockerfile
25
Dockerfile
@@ -2,21 +2,34 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
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 . .
|
||||
|
||||
# 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
|
||||
# 3. Publish to a FLAT directory
|
||||
# We use -o /app/publish and ensure no extra subfolders are created
|
||||
RUN dotnet publish "SampleApi/SampleApi.csproj" \
|
||||
-c Release \
|
||||
-o /app/publish \
|
||||
--no-restore \
|
||||
/p:UseAppHost=false
|
||||
|
||||
# STAGE 2: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the contents of the publish folder directly into /app
|
||||
# Copy the contents directly
|
||||
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
|
||||
|
||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||
Reference in New Issue
Block a user