我们有一个 Dockerfile
,其中包含以下形式的命令
RUN dotnet restore --no-cache -s http://localhost:8081/repository/nuget-hosted/
当我们运行时
docker build .
这一行遇到的错误是
Retrying 'FindPackagesByIdAsyncCore' for source 'http://localhost:8081/repository/nuget-repo-name/FindPackagesById()?id='Package.Name''.
An error occurred while sending the request.
Couldn't connect to server
/usr/share/dotnet/sdk/2.1.101/NuGet.targets(104,5): error : Failed to retrieve information about 'Package.Name' from remote source 'http://localhost:8081/repository/nuget-repo-name/FindPackagesById()?id='Package.Name''.
但是,当我们在命令行中运行相同的命令时,dotnet restore
是成功的。
有问题的 nuget 服务器在同一台机器上运行。如果我们在浏览器中点击相同的 URL,则成功。
我们如何使运行在 localhoat:8081 的 nuget 服务器在 docker build
中可访问,以便成功创建 docker 镜像?
最佳答案
如 https://stackoverflow.com/users/1080064/tkausl 所述替换 http://localhost:8081/repository/nuget-hosted/与 http://1.2.3.4:8081/repository/nuget-hosted/其中 1.2.3.4 是解决问题的实际 IP 地址。
关于linux - docker build 无法连接到 http 服务器,即使它可以在命令行上访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50952004/