可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp
Docker command docker build -t aspnetapp
.
I am getting an error for docker build command as
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\aspnetapp.csproj]
[1]PS C:\Users\pssharma\dotnet-docker-samples\aspnetapp> docker build -t aspnetapp .
Sending build context to Docker daemon 2.444MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
---> eb21d939e0d8
Step 2/10 : WORKDIR /app
---> Using cache
---> d4ec30216ed7
Step 3/10 : COPY *.csproj ./
---> Using cache
---> 2ff39b5e6cb4
Step 4/10 : RUN dotnet restore
---> Running in 776764a35311
Restoring packages for C:\app\aspnetapp.csproj...
Restoring packages for C:\app\aspnetapp.csproj...
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\asp
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : An error occurred while sending the request. [C:\app\aspnetapp.csproj]
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : The operation timed out [C:\app\aspnetapp.csproj]
The following command returned a non-zero code: 1
powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore
回答1:
For me, this issue appeared randomly (along with multiple similar issues, such as "permission denied for nuget" etc. To fix that, restart Visual Studio)
For windows, it was fixed by restarting docker service and restarting Visual Studio (2017).
- Shut down Docker and Visual Studio
- Winkey + R, type in services.msc
- Find Docker for Windows Service and restart it (restarting Docker normally is not enough)
- Start Docker and Visual Studio
回答2:
I got this working by passing in docker build environment variables from the command line like so:
docker build --build-arg HTTP_PROXY=http://{un}:{pw}@{proxyhost}:{port} --build-arg HTTPS_PROXY=http://{un}:{pw}@{proxyhost}:{port} -t aspnetapp
.
*note that your username must be url encoded (ei. DOMAIN\name => DOMAIN%5Cname)
回答3:
Just add --network=host
option to docker build
docker build -t aspnetapp . --network=host
回答4:
This appears to happen when there are multiple network adaptors present for the host and the priority of said adaptor is misconfigured. Run the following to display a table of your network adaptors:
Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
You want your primary adaptor (in my case wifi) to have the lowest InterfaceMetric.
Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 1
My network adaptor table for reference:
See this github thread for more information:
https://github.com/docker/for-win/issues/2760#issuecomment-430889666
回答5:
Had the same issue, the problem was a missing dependency used by NuGet
.
I am using the microsoft/dotnet:sdk
image, and it works after installing libcurl3
to my image.
Try adding
RUN apt-get update && apt-get install -y libcurl3
to your Dockerfile
before restoring.
if it doesn't work, try restarting your Docker instance.
edit
: if that doesn't help you, there is this open issue on the NuGet github
where some people are trying to solve the same problem.
edit2
:added Ignas solution: restarting docker instance.
回答6:
In my case, in Dockerfile
, I have
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
and
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
But I only have .net 2.1
installed (view by dotnet --list-sdks
). So I have to change 2.2
to 2.1
to make it work.
回答7:
Open CMD or Powershell and run: dotnet nuget locals http-cache --clear
https://status.nuget.org/
回答8:
@patrickbadley's solution works for me.
I got this working by passing in docker build environment variables
from the command line like so:
docker build --build-arg
HTTP_PROXY=http://{un}:{pw}@{proxyhost}:{port} --build-arg
HTTPS_PROXY=http://{un}:{pw}@{proxyhost}:{port} -t aspnetapp .
回答9:
I had the same issue on Debian 9. I fudge the error with disconnecting from local network. It works for me because I did not change anything on codebase and I do not need to get packages from nuget.
回答10:
I got this resolved on my Windows 10 Machine by Disabling Avast Antivirus and unInstalling McAffee Antivirus.
- Right click the Avast Icon in the Notification Tab
- Select Avast Shields Control
- Click on "Disable Until Computer is Restarted".
And you can now run the Docker Build Successfully.
I can give Further Assistance if needed.
回答11:
After one hour fighting with proxy, finally following solution worked just fine for me:
docker build --build-arg HTTP_PROXY=http://xxxx.com:8080 --build-arg HTTPS_PROXY=http://yyyy:8080 -t kdekarin/aspnet .
See @patrickbadley's comment for more info!