C# VS2019 Docker支持和Dockerfile失败

C# VS2019 Docker支持和Dockerfile失败,c#,.net,docker,dockerfile,visual-studio-2019,C#,.net,Docker,Dockerfile,Visual Studio 2019,VS2019,创建了具有Windows Docker支持的全新mvc应用程序 Dockerfile内容(从模板创建): 当我执行: docker build -t mvc1 . 我得到以下错误: C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5):错误: 无法加载源的服务索引 . [C:\src\mvc1\mvc1.csproj] C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(

VS2019,创建了具有Windows Docker支持的全新mvc应用程序

Dockerfile内容(从模板创建):

当我执行:

docker build -t mvc1 .
我得到以下错误:

C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5):错误: 无法加载源的服务索引 . [C:\src\mvc1\mvc1.csproj] C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5):错误:否 这种主机已知[C:\src\mvc1\mvc1.csproj]命令'cmd/S/C dotnet restore“mvc1/mvc1.csproj”返回一个非零代码:1

编辑: 我已将这一行添加到Dockerfile:

RUN ping google.com
并获得:

Step 4/17 : RUN ping google.com
 ---> Running in 6633175b21a8
Ping request could not find host google.com. Please check the name and try again.
编辑2:

因此,当我编辑.csproj文件并删除这一行时:

        <Project Sdk="Microsoft.NET.Sdk.Web">

          <PropertyGroup>
            <TargetFramework>netcoreapp2.2</TargetFramework>
            <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
          </PropertyGroup>


          <ItemGroup>
            <PackageReference Include="Microsoft.AspNetCore.App" />
            <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <!-- REMOVED -->
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.12" />
  <!-- REMOVED -->
          </ItemGroup>

        </Project>

netcoreapp2.2
过程中

它确实有效。为什么呢

我也有同样的问题。此链接解决了我的问题:

我的默认以太网适配器没有最低指标 检查:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
设置为:

Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4

你的机器能打吗?是的。我能点击它你试过
dotnet restore-s吗https://api.nuget.org/v3/index.json
?@Shymep当我在CMD中运行此命令时,此操作有效。但是,当我运行docker build时,我仍然会得到“无法加载源的服务索引”。请参阅我的Edit2。您可以在回答中添加一些解释“dotnet restore”命令从internet还原nuget包。如果默认docker以太网适配器未连接到internet,则任务失败。通过“设置NetIPInterface”,您可以将以太网适配器设置为具有internet连接的适配器。在我的例子中,它的名字是“以太网”
Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4