根据这本书
.NET Microservices: Architecture for Containerized .NET Applications (Microsoft EBook)
,
第一个构建指令是冗余的
因为publish指令也会生成,它就在第一条生成指令之后。第94(86)页,第10行。
这是这本书的一个简短摘录:
1 FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
2 WORKDIR /app
3 EXPOSE 80
4
5 FROM microsoft/dotnet:2.1-sdk AS build
6 WORKDIR /src
7 COPY src/Services/Catalog/Catalog.API/Catalog.API.csproj â¦
8 COPY src/BuildingBlocks/HealthChecks/src/Microsoft.AspNetCore.HealthChecks â¦
9 COPY src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions.HealthChecks â¦
10 COPY src/BuildingBlocks/EventBus/IntegrationEventLogEF/ â¦
11 COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj â¦
12 COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj â¦
13 COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj â¦
14 COPY src/BuildingBlocks/WebHostCustomization/WebHost.Customization â¦
15 COPY src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions â¦
16 COPY src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions â¦
17 RUN dotnet restore src/Services/Catalog/Catalog.API/Catalog.API.csproj
18 COPY . .
19 WORKDIR /src/src/Services/Catalog/Catalog.API
20 RUN dotnet build Catalog.API.csproj -c Release -0 /app
21
22 FROM build AS publish
23 RUN dotnet publish Catalog.API.csproj -c Release -0 /app
24
25 FROM base AS final
26 WORKDIR /app
27 COPY --from=publish /app
28 ENTRYPOINT ["dotnet", "Catalog.API.dll"]
对于最终的优化,恰好20行是多余的,
因为第23行也构建了应用程序,本质上是正确的
在第20行之后,还有一个耗时的命令。