c# - VS2019 Docker 支持和 Dockerfile 失败

标签 c# .net docker dockerfile visual-studio-2019

VS2019,创建了一个全新的 mvc 应用程序,支持 Windows Docker。

Dockerfile 内容(从模板创建):

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY ["mvc1.csproj", "mvc1/"]
RUN dotnet restore "mvc1/mvc1.csproj"
COPY . .
WORKDIR "/src/mvc1"
RUN dotnet build "mvc1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "mvc1.csproj" -c Release -o /app

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

enter image description here

当我执行:
docker build -t mvc1 .

我收到以下错误:

C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\mvc1\mvc1.csproj] C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : No such host is known [C:\src\mvc1\mvc1.csproj] The command 'cmd /S /C dotnet restore "mvc1/mvc1.csproj"' returned a non-zero code: 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>

它确实有效。这是为什么?

最佳答案

我有同样的问题。此链接解决了我的问题:
https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/
我的默认以太网适配器没有最低指标
检查:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
设置:
Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4

关于c# - VS2019 Docker 支持和 Dockerfile 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57791748/

相关文章:

c# - 为什么 System.-Encoding 和默认编码不同(.NET Core)?

c# - 如何在 ASP MVC 中将数据传递到共享 View ?

c# - 集合中的重复键处理

c# - 如何根据 Authorization header 值授权请求?

mysql - 在 docker-compose 中使用 MySQL 初始化 Hibernate 时连接被拒绝

docker - 无法在Windows中运行boot2docker-vm

c# - 非常非常大的 C# float

c# - AES 解密的消息与原始消息不匹配

C# Invalidate 不调用 paint 方法

javascript - Node.js 应用程序中的 SequelizeConnectionError