我有。net核心解决方案包含一些微服务项目,当我试图在dokcer上发布我的项目时,我得到一些错误
my dockerfile is:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Services/Identity/Identity.API/Identity.API.csproj", "Services/Identity/Identity.API/"]
COPY ["BuildingBlocks/Core/Core/Core.csproj", "BuildingBlocks/Core/Core/"]
COPY ["BuildingBlocks/Core/Core.Common/Core.Common.csproj", "BuildingBlocks/Core/Core.Common/"]
COPY ["BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj", "BuildingBlocks/WebHostCustomization/WebHost.Customization/"]
COPY ["BuildingBlocks/Core/Core.WebApi/Core.WebApi.csproj", "BuildingBlocks/Core/Core.WebApi/"]
COPY ["BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj", "BuildingBlocks/EventBus/IntegrationEventLogEF/"]
COPY ["BuildingBlocks/EventBus/EventBus/EventBus.csproj", "BuildingBlocks/EventBus/EventBus/"]
COPY ["BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj", "BuildingBlocks/EventBus/EventBusRabbitMQ/"]
RUN dotnet restore "Services/Identity/Identity.API/Identity.API.csproj"
COPY . .
WORKDIR "/src/Services/Identity/Identity.API"
RUN dotnet build "Identity.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Identity.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Identity.API.dll"]
我的输出是:
#19 240.8 Restored /src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj (in 43.14 sec).
#19 241.0 Restored /src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj (in 148 ms).
#19 241.1 Restored /src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj (in 40 ms).
#19 275.6 Failed to download package 'System.Text.Json.4.7.2' from 'https://api.nuget.org/v3-flatcontainer/system.text.json/4.7.2/system.text.json.4.7.2.nupkg'.
#19 275.6 The download of 'https://api.nuget.org/v3-flatcontainer/system.text.json/4.7.2/system.text.json.4.7.2.nupkg' timed out because no data was received for 60000ms.
#19 275.6 Exception of type 'System.TimeoutException' was thrown.
#19 282.3 Failed to download package 'AutoMapper.9.0.0' from 'https://api.nuget.org/v3-flatcontainer/automapper/9.0.0/automapper.9.0.0.nupkg'.
#19 282.3 The download of 'https://api.nuget.org/v3-flatcontainer/automapper/9.0.0/automapper.9.0.0.nupkg' timed out because no data was received for 60000ms.
#19 282.3 Exception of type 'System.TimeoutException' was thrown.
#19 282.7 Failed to download package 'System.Threading.4.0.11' from 'https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg'.
#19 282.7 The download of 'https://api.nuget.org/v3-flatcontainer/system.threading/4.0.11/system.threading.4.0.11.nupkg' timed out because no data was received for 60000ms.
#19 282.7 Exception of type 'System.TimeoutException' was thrown.
#19 284.4 Failed to download package 'System.Collections.4.3.0' from 'https://api.nuget.org/v3-flatcontainer/system.collections/4.3.0/system.collections.4.3.0.nupkg'.
#19 284.4 The download of 'https://api.nuget.org/v3-flatcontainer/system.collections/4.3.0/system.collections.4.3.0.nupkg' timed out because no data was received for 60000ms.
#19 284.4 Exception of type 'System.TimeoutException' was thrown.
#19 287.3 Failed to download package 'System.Diagnostics.Process.4.3.0' from 'https://api.nuget.org/v3-flatcontainer/system.diagnostics.process/4.3.0/system.diagnostics.process.4.3.0.nupkg'.
#19 287.3 The download of 'https://api.nuget.org/v3-flatcontainer/system.diagnostics.process/4.3.0/system.diagnostics.process.4.3.0.nupkg' timed out because no data was received for 60000ms.
#19 287.3 Exception of type 'System.TimeoutException' was thrown.
#19 288.2 Restored /src/BuildingBlocks/Core/Core.Common/Core.Common.csproj (in 47.12 sec).
#19 288.8 Failed to download package 'System.ComponentModel.4.0.1' from 'https://api.nuget.org/v3-flatcontainer/system.componentmodel/4.0.1/system.componentmodel.4.0.1.nupkg'.
#19 288.8 The download of 'https://api.nuget.org/v3-flatcontainer/system.componentmodel/4.0.1/system.componentmodel.4.0.1.nupkg' timed out because no data was received for 60000ms.
#19 288.8 Exception of type 'System.TimeoutException' was thrown.
#19 289.5 Failed to download package 'System.Diagnostics.Process.4.1.0' from 'https://api.nuget.org/v3-flatcontainer/system.diagnostics.process/4.1.0/system.diagnostics.process.4.1.0.nupkg'.
#19 289.5 The download of 'https://api.nuget.org/v3-flatcontainer/system.diagnostics.process/4.1.0/system.diagnostics.process.4.1.0.nupkg' timed out because no data was received for 60000ms.
#19 289.5 Exception of type 'System.TimeoutException' was thrown.
#19 290.0 Failed to download package 'System.ComponentModel.Annotations.4.5.0' from 'https://api.nuget.org/v3-flatcontainer/system.componentmodel.annotations/4.5.0/system.componentmodel.annotations.4.5.0.nupkg'.
#19 290.0 The download of 'https://api.nuget.org/v3-flatcontainer/system.componentmodel.annotations/4.5.0/system.componentmodel.annotations.4.5.0.nupkg' timed out because no data was received for 60000ms.
#19 290.0 Exception of type 'System.TimeoutException' was thrown.
#19 291.1 Failed to download package 'System.Text.Encoding.4.0.11' from 'https://api.nuget.org/v3-flatcontainer/system.text.encoding/4.0.11/system.text.encoding.4.0.11.nupkg'.
#19 291.1 The download of 'https://api.nuget.org/v3-flatcontainer/system.text.encoding/4.0.11/system.text.encoding.4.0.11.nupkg' timed out because no data was received for 60000ms.
#19 291.1 Exception of type 'System.TimeoutException' was thrown.
#19 293.1 Failed to download package 'Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.16.0' from 'https://api.nuget.org/v3-flatcontainer/microsoft.applicationinsights.windowsserver.telemetrychannel/2.16.0/microsoft.applicationinsights.windowsserver.telemetrychannel.2.16.0.nupkg'.
#19 293.1 The download of 'https://api.nuget.org/v3-flatcontainer/microsoft.applicationinsights.windowsserver.telemetrychannel/2.16.0/microsoft.applicationinsights.windowsserver.telemetrychannel.2.16.0.nupkg' timed out because no data was received for 60000ms.
#19 293.1 Exception of type 'System.TimeoutException' was thrown.
#19 295.2 Failed to download package 'System.Memory.4.5.1' from 'https://api.nuget.org/v3-flatcontainer/system.memory/4.5.1/system.memory.4.5.1.nupkg'.
#19 295.2 The download of 'https://api.nuget.org/v3-flatcontainer/system.memory/4.5.1/system.memory.4.5.1.nupkg' timed out because no data was received for 60000ms.
#19 295.2 Exception of type 'System.TimeoutException' was thrown.
#19 297.2 Failed to download package 'System.ComponentModel.Annotations.4.1.0' from 'https://api.nuget.org/v3-flatcontainer/system.componentmodel.annotations/4.1.0/system.componentmodel.annotations.4.1.0.nupkg'.
#19 297.2 The download of 'https://api.nuget.org/v3-flatcontainer/system.componentmodel.annotations/4.1.0/system.componentmodel.annotations.4.1.0.nupkg' timed out because no data was received for 60000ms.
#19 297.2 Exception of type 'System.TimeoutException' was thrown.
#19 300.5 Failed to download package 'System.IO.FileSystem.4.0.1' from 'https://api.nuget.org/v3-flatcontainer/system.io.filesystem/4.0.1/system.io.filesystem.4.0.1.nupkg'.
#19 300.5 The download of 'https://api.nuget.org/v3-flatcontainer/system.io.filesystem/4.0.1/system.io.filesystem.4.0.1.nupkg' timed out because no data was received for 60000ms.
#19 300.5 Exception of type 'System.TimeoutException' was thrown.
#19 1287.9 Restored /src/Services/Identity/Identity.API/Identity.API.csproj (in 18.19 min).
#19 DONE 1290.5s
当我输入地址
时https://api.nuget.org/v3-flatcontainer/system.io.filesystem/4.0.1/system.io.filesystem.4.0.1.nupkg在浏览器中,包被下载,但是Docker不能从同一个地址下载
我的操作系统是windows 10,我在上面使用docker桌面来构建镜像,
我用Visual Studio和Docker命令(Docker -compose up)两种方式创建了图像我遇到了同样的问题在这两个方法
可能是SSL的问题因为另一个错误消息是:
Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/microsoft.extensions.hosting.abstractions/index.json'.
The SSL connection could not be established, see inner exception.
Received an unexpected EOF or 0 bytes from the transport stream.
如何解决
我也有同样的问题,原因是我的网速慢。在dotnet恢复命令中必须使用--disable-parallel
标志像
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Services/Identity/Identity.API/Identity.API.csproj", "Services/Identity/Identity.API/"]
COPY ["BuildingBlocks/Core/Core/Core.csproj", "BuildingBlocks/Core/Core/"]
COPY ["BuildingBlocks/Core/Core.Common/Core.Common.csproj", "BuildingBlocks/Core/Core.Common/"]
COPY ["BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj", "BuildingBlocks/WebHostCustomization/WebHost.Customization/"]
COPY ["BuildingBlocks/Core/Core.WebApi/Core.WebApi.csproj", "BuildingBlocks/Core/Core.WebApi/"]
COPY ["BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj", "BuildingBlocks/EventBus/IntegrationEventLogEF/"]
COPY ["BuildingBlocks/EventBus/EventBus/EventBus.csproj", "BuildingBlocks/EventBus/EventBus/"]
COPY ["BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj", "BuildingBlocks/EventBus/EventBusRabbitMQ/"]
RUN dotnet restore "Services/Identity/Identity.API/Identity.API.csproj" --disable-parallel
COPY . .
WORKDIR "/src/Services/Identity/Identity.API"
RUN dotnet build "Identity.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Identity.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Identity.API.dll"]
这个标志的缺点是你的docker构建时间上升了很多