首页 > 解决方案 > Visual Studio docker 跳过项目,因为找不到,然后恢复并最终构建但速度很慢

问题描述

我试图了解一个缓慢的(香草默认工作人员服务为 30 秒)docker build 过程,我从中引用了一个项目类库,我有以下 docker 文件:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj", "Libertas.Tickers.Stream/"]
RUN dotnet restore "Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj"
COPY . .
WORKDIR "/src/Libertas.Tickers.Stream"
RUN dotnet build "Libertas.Tickers.Stream.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Libertas.Tickers.Stream.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Libertas.Tickers.Stream.dll"]

当我右键单击并构建项目 docker 文件时,我看到未找到的行:

4>Sending build context to Docker daemon  1.504MB
4>
4>Step 1/17 : FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
4> ---> 7be7431e6153
4>Step 2/17 : WORKDIR /app
4> ---> Using cache
4> ---> dda29b40eefe
4>Step 3/17 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
4> ---> c4155a9104a8
4>Step 4/17 : WORKDIR /src
4> ---> Using cache
4> ---> 8424cf707044
4>Step 5/17 : COPY ["Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj", "Libertas.Tickers.Stream/"]
4> ---> 791c6f181247
4>Step 6/17 : RUN dotnet restore "Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj"
4> ---> Running in 870556eed511
4>  Determining projects to restore...
4>  Skipping project "/src/Libertas.Common/Libertas.Common.csproj" because it was not found.
4>  Skipping project "/src/Libertas.Common/Libertas.Common.csproj" because it was not found.
4>  Restored /src/Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj (in 8.01 sec).
4>Removing intermediate container 870556eed511
4> ---> 06c7118a1cb7
4>Step 7/17 : COPY . .
4> ---> e8f81702a397
4>Step 8/17 : WORKDIR "/src/Libertas.Tickers.Stream"
4> ---> Running in fec96fed84a3
4>Removing intermediate container fec96fed84a3

然后最终恢复包并构建没有错误:

4> ---> 16aacaa1da46
4>Step 9/17 : RUN dotnet build "Libertas.Tickers.Stream.csproj" -c Release -o /app/build
4> ---> Running in ffd594ede300
4>Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
4>Copyright (C) Microsoft Corporation. All rights reserved.
4>
4>  Determining projects to restore...
4>  Restored /src/PolygonIo.WebSocket/PolygonIo.WebSocket.csproj (in 5.98 sec).
4>  Restored /src/Unified.EnterpriseIntegration/Unified.EnterpriseIntegration.csproj (in 9.91 sec).
4>  Restored /src/Libertas.Common/Libertas.Common.csproj (in 9.92 sec).
4>  Restored /src/Libertas.Tickers.Stream/Libertas.Tickers.Stream.csproj (in 9.92 sec).
4>/usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(4364,5): warning MSB3026: Could not copy "/root/.nuget/packages/system.reactive/4.4.1/buildTransitive/netcoreapp3.0/../../lib/netstandard2.0/System.Reactive.dll" to "/app/build/System.Reactive.dll". Beginning retry 1 in 1000ms. The process cannot access the file '/app/build/System.Reactive.dll' because it is being used by another process.  [/src/Unified.EnterpriseIntegration/Unified.EnterpriseIntegration.csproj]
4>  PolygonIo.WebSocket -> /app/build/PolygonIo.WebSocket.dll
4>  Unified.EnterpriseIntegration -> /app/build/Unified.EnterpriseIntegration.dll
4>  Libertas.Common -> /app/build/Libertas.Common.dll
4>  Libertas.Tickers.Stream -> /app/build/Libertas.Tickers.Stream.dll
4>Build succeeded.

有什么方法可以跳过这个未找到的步骤或加快进程,许多 docker 镜像都在做同样的事情,它需要很长时间来构建整个解决方案(包含许多 docker worker 项目)。

标签: visual-studiodocker-compose

解决方案


推荐阅读