4
votes

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

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

enter image description here

When I execute:

docker build -t mvc1 .

I get the following errors:

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

EDIT: I've added this line to Dockerfile:

RUN ping google.com

and get:

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.

EDIT 2:

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?

1
Is your machine able to hit api.nuget.org/v3/index.json?m00nbeam360.0
yes. i'm able to hit itShaneKm
Did you try dotnet restore -s https://api.nuget.org/v3/index.json?Alex Kovanev
@Shymep this worked when i run this command in CMD. But when I run docker build I still get " Unable to load the service index for source api.nuget.org/v3/index.json."ShaneKm
Please see my EDIT2ShaneKm

1 Answers

4
votes

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

Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4