Dotnet Restore在Docker构建中失败

时间:2018-12-10 11:37:52

标签: docker nuget dotnet-restore

您好,我尝试dockerize一个ASP NET Core 2.1应用程序,而docker build在执行dotnet restore时失败。 我已经检查了其他线程来解决此特定问题
Nuget connection attempt failed "Unable to load the service index for source"

那里提供的解决方案对我没有帮助。

Dockerfile

ARG serverPath=./Core/Server

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app


COPY ./Core/Server/*.csproj ./
RUN dotnet restore  //fails here

COPY ./Core/Server/ ./
RUN dotnet publish -c Release -o out  


FROM microsoft/dotnet:2.1-aspnetcore-runtime 
WORKDIR /app
COPY --from=build-env /app/out  .
ENTRYPOINT ["dotnet","Server.dll"]

docker build的输出

$ docker build -t server .
Sending build context to Docker daemon  11.13MB
Step 1/11 : ARG serverPath=./Core/Server
Step 2/11 : FROM microsoft/dotnet:sdk AS build-env
 ---> 343e2dc38168
Step 3/11 : WORKDIR /app
 ---> Using cache
 ---> e9b75480ecb9
Step 4/11 : COPY ./Core/Server/*.csproj ./
 ---> Using cache
 ---> 2de864bedf6a
Step 5/11 : RUN dotnet restore 
 ---> Running in 2fc6963e7e2c
  Restoring packages for /app/Server.csproj...
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/app/Server.csproj]
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error :   The SSL connection could not be established, see inner exception. [/app/Server.csproj]
/usr/share/dotnet/sdk/2.2.100/NuGet.targets(114,5): error :   Authentication failed because the remote party has closed the transport stream. [/app/Server.csproj]
The command '/bin/sh -c dotnet restore -p:RestoreUseSkipNonexistentTargets=false -nowarn:msb3202,nu1503' returned a non-zero code: 1

3 个答案:

答案 0 :(得分:3)

尝试一下

docker network ls

这应该列出尝试运行docker build的networkIDs

docker build --network=<networkid> tag=<tag>

尝试以上列出的所有网络,它将与一个主机网络兼容。

答案 1 :(得分:0)

尝试将您的DNS服务器更新为“固定”(默认应为8.8.8.8)。

我在“设置”->“网络”->“ DNS服务器”中找到了这个

答案 2 :(得分:0)

如果在 Windows 7 或 Windows Server 2008 R2 上,启用 TLS 1.2 以与新的 NuGet 服务器通信。 Microsoft DevBlogs on NuGet TLS status