Skip to content

Commit 873127b

Browse files
Fix Dockerfile
Fix (and simplify) the ASP.NET Core dockerfile.
1 parent d388bf7 commit 873127b

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2-
3-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
4-
WORKDIR /app
5-
EXPOSE 80
6-
7-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
8-
1+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
ARG TARGETARCH
3+
ARG CONFIGURATION="Release"
94
ARG DOTNET_PUBLISH_ARGS=""
105

11-
WORKDIR /src
12-
COPY ["examples/net8.0/aspnetcore/aspnetcore.csproj", "examples/net8.0/aspnetcore/"]
13-
RUN dotnet restore "examples/net8.0/aspnetcore/aspnetcore.csproj"
14-
COPY . .
15-
WORKDIR "/src/examples/net8.0/aspnetcore"
16-
RUN dotnet build "aspnetcore.csproj" -c Release -o /app/build
6+
COPY . /source
7+
WORKDIR /source
8+
9+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1710

18-
FROM build AS publish
19-
RUN dotnet publish "aspnetcore.csproj" -c Release -o /app/publish ${DOTNET_PUBLISH_ARGS}
11+
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
12+
dotnet publish "examples/net8.0/aspnetcore/aspnetcore.csproj" --arch "${TARGETARCH}" --configuration "${CONFIGURATION}" --output /app "${DOTNET_PUBLISH_ARGS}"
2013

21-
FROM base AS final
14+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS final
2215
WORKDIR /app
23-
COPY --from=publish /app/publish .
24-
RUN apt-get update && apt-get install -y curl
16+
EXPOSE 8080
17+
18+
COPY --from=build /app .
2519
ENTRYPOINT ["dotnet", "aspnetcore.dll"]

0 commit comments

Comments
 (0)