[英]Connection refused from host into a linux container with Docker for Windows
我在网上找到了很多关于这个问题的材料,但是我找不到解决方案。 他们中的大多数也相当老(几年),同时情况可能会发生很大变化。
我在我的Windows 机器上运行Docker Desktop Community v 2.3.0.3和一个简单的容器,其中包含Ubuntu和在localhost上运行的Rails应用程序:
容器使用以下方式运行:
docker run -p 5000:5000 rails:6.0.3 foreman start
我想通过浏览器从我的 Windows 主机连接到 Rails 应用程序,但连接被拒绝。
服务器已启动并正在运行:
> docker exec 3c167e206f60 wget localhost:5000
--2020-06-06 08:21:26-- http://localhost:5000/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:5000... connected.
HTTP request sent, awaiting response... 200 OK
端口转发似乎无法正常工作(从 WSL 运行,但同样通过 Chrome 从 Windows 运行):
> wget localhost:5000
--2020-06-06 10:22:50-- http://localhost:5000/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:5000... failed: Connection refused.
使用容器地址而不是本地主机时,它不起作用,要么:
> docker inspect --format '{{ .NetworkSettings.IPAddress }}' 3c167e206f60
172.17.0.2
> wget 172.17.0.2:5000
--2020-06-06 10:29:02-- http://172.17.0.2:5000/
Connecting to 172.17.0.2:5000... failed: Resource temporarily unavailable.
另外(可能正如预期的那样),我在ifconfig (来自 WSL)或ipconfig (来自 Windows)output 中看不到任何与 docker 相关的条目。
我也试过docker run --net host
参数,这也没有帮助。
理想情况下,我更喜欢不需要我修改 Windows 主机设置(网络设置等)的解决方案,以避免破坏其他场景的可能性。
我已经为这个问题苦苦挣扎了好几天。 对我有用的是:
这似乎重置了所有 HyperV 虚拟网络接口。 卸载 Docker Desktop 可能不是必需的,但由于它至少依赖于其中一些功能,我觉得做一个完整的循环是最明智的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.