Linux docker build无法连接到http服务器,即使它可以在命令行上访问
我们有一个Linux docker build无法连接到http服务器,即使它可以在命令行上访问,linux,docker,.net-core-2.0,nuget-server,Linux,Docker,.net Core 2.0,Nuget Server,我们有一个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/FindPacka
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还原
是成功的
有问题的nuget服务器正在同一台计算机上运行。如果我们在浏览器中点击相同的URL,这是成功的
我们如何使运行在localhoat:8081的nuget服务器在
docker build
中可访问,以便成功创建docker映像?如前所述,替换为其中1.2.3.4是解决问题的实际ip地址。localhost
在主机上与在主机上的localhost
不同我建议您使用主机的docker网络ip地址运行,而不是提供“localhost”;因为在您的情况下,docker查找容器中运行的本地主机,因此如果您提供主机的docker网络ip地址,那么它将尝试访问主机。我希望这能帮助你解决你的问题。