VS2019 Docker支持和Dockerfile失败 [英] VS2019 Docker support and Dockerfile failing

查看:77
本文介绍了VS2019 Docker支持和Dockerfile失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS2019,创建了一个具有Windows Docker支持的全新mvc应用.

VS2019, created a brand new mvc app with Windows Docker support.

Dockerfile内容(从模板创建):

Dockerfile contents (created from template):

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"]

执行时:

docker build -t mvc1 .

我收到以下错误:

C:\ Program Files \ dotnet \ sdk \ 2.2.401 \ NuGet.targets(123,5):错误:无法加载源的服务索引 https://api.nuget.org/v3/index.json .[C:\ src \ mvc1 \ mvc1.csproj]C:\ Program Files \ dotnet \ sdk \ 2.2.401 \ NuGet.targets(123,5):错误:否这样的主机是已知的[C:\ src \ mvc1 \ mvc1.csproj]命令'cmd/S/Cdotnet restore"mvc1/mvc1.csproj"'返回了非零代码:1

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中:

I've added this line to 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.

因此,事实证明,当我编辑.csproj文件并删除此行时:

So, it turns out when I edit my .csproj file and remove this line:

        <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>

它确实起作用.这是为什么?

It DOES work. Why is that?

推荐答案

我遇到了同样的问题.此链接解决了我的问题: https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/

I had the same problem. This links solved my problem: https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/

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

My default Ethernet Adapter didn't have the lowest metric Check with:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending

设置为:

Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4

这篇关于VS2019 Docker支持和Dockerfile失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆