4

im trying to run "Build Docker Image" in Visual Studio 2019 but it fails on restore step.

Here's the DockerFile:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

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

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

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

Here's the error message while building the image:

1>C:\Program Files\dotnet\sdk\3.1.402\NuGet.targets(128,5): error :   No such host is known. [C:\src\OwnProject\OwnProject.csproj]
1>C:\Program Files\dotnet\sdk\3.1.402\NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\OwnProject\OwnProject.csproj]

What could be the reason for this? Is it related to DNS?

If I run docker run -it --dns=8.8.8.8 mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 in powershell, i can ping google.com, but if I exclude the "--dns" I can only ping it. Could that be the reason why the restore fails, problem resolving addresses? If so, How do I fix it? Is it possible to set DNS-server in the DockerFile?

I've looked in some nuget configuration files, for example on user level (Users\AD-name\AppData\Roaming\NuGet\NuGet.Config):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

...which to me seems fine? I've also tried to disable networks adapter, changed interfacemetric's to prioritize adapters, upgraded .net core sdk to 3.1.402, but nothing seems to work...

Any ideas/suggestions would be helpful.

1

1 Answer 1

1

You have to set default network adapter for docker As Docker uses the lowest InterfaceAlias adapter you can see this url for more details https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/

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

This should give you an output like this one: Net IP Interface list Lowest Connector is disconnected

My interface ‘Ethernet’ was disconnected and therefore resulted in my network problems. To fix this, I moved my ‘Ethernet’ interface behind the first interface that was connected using this command:

PowerShell Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4

Not the answer you're looking for? Browse other questions tagged or ask your own question.