简体   繁体   English

无法联系Windows主机上的Docker容器

[英]Cannot contact docker container on Windows host

tl;dr summary of the problem: tl; dr问题的摘要:

  • Application launches successfully within container, binds to 127.0.0.1:8080 within the container, and successfully services web requests, but only within the container 应用程序在容器内成功启动,绑定到容器内的127.0.0.1:8080,并成功服务Web请求,但仅在容器内
  • docker ps -a confirms that port 8080 is being exposed docker ps -a确认端口8080已暴露
  • I cannot communicate with the application from the host using the container's actual IP address when I request http://[Container IP address]:8080 当我请求http:// [Container IP address]:8080时,无法使用容器的实际IP地址从主机与应用程序进行通信
  • The host is running Windows 10 主机正在运行Windows 10
  • The Windows Firewall is completely disabled for troubleshooting Windows防火墙已完全禁用以进行故障排除

To troubleshoot I have created the simplest possible application to run in a dockers container, an F# / Suave application like so: 为了排除故障,我创建了最简单的应用程序以在dockers容器中运行,这是一个F#/ Suave应用程序,如下所示:

open Suave
[<EntryPoint>]
let main args =

    startWebServer defaultConfig (Successful.OK "Hello World!")
    0

Which works fine, returning a simple "Hello World!" 效果很好,返回了一个简单的“ Hello World!” when I run it locally. 当我在本地运行时。

To containerize the app I have followed the instructions at " Dockerize a .NET Core application " which instructs me to run the container like 为了对应用程序进行容器化,我已按照“对Docker进行.NET Core应用程序化 ”中的说明进行操作,该说明指导我像

$ docker run -d -p 8080:80 --name myapp aspnetapp

I cannot connect to the "website" at http://localhost:80 nor http://localhost:8080 , which apparently is a common problems for Docker users running Windows. 我无法连接到http:// localhost:80http:// localhost:8080上的“网站”,这显然是运行Windows的Docker用户的常见问题。 However the solution that seems to have fixed this problem for every other Windows user on the internet, running 但是,该解决方案似乎已为Internet上运行的所有其他Windows用户解决了此问题

docker inspect myapp

and then hitting the resulting IPAddress, does not work either. 然后点击生成的IPAddress也不起作用。 I get: 我得到:

在此处输入图片说明

Hitting both http://172.17.0.2:80 and http://172.17.0.2:8080 in Chrome gives me "Site can't be reached." 在Chrome中同时点击http://172.17.0.2:80http://172.17.0.2:8080都会使我“无法访问该网站”。

Also worth noting, when I run 另外值得注意的是,当我跑步时

docker logs myapp

The only line is 唯一的一行是

[17:43:21 INF] Smooth! Suave listener started in 73.476ms with binding 127.0.0.1:8080

As a guess, I have also tried 猜测,我也尝试过

ipconfig

在此处输入图片说明

and then hitting the IP address of the Docker NAT adapter, but this also results in an unreachable site. 然后点击Docker NAT适配器的IP地址,但这也会导致无法访问的站点。

UPDATE : 更新

Another observation which might or might not be relevant: Many online tutorials suggest that under Windows you need to directly connect to the IP Address of the container, and to get that IP address by running 另一个可能不相关的观察:许多在线教程建议在Windows下,您需要直接连接到容器的IP地址,并通过运行来获取该IP地址。

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myapp

which for me, always yields: 对我来说,总是产生:

When I run a vanilla 当我运行香草

docker inspect myapp 码头工人检查myapp

the resulting JSON is not structured exactly like the recommended query. 结果JSON的结构与建议的查询不完全相同。 I get a bridge node, but no nat node: 我得到一个节点,但没有nat节点:

在此处输入图片说明

您的应用程序说它绑定到localhost:8080,但是您正在发布端口80。停止容器,然后使用以下命令重新运行:

docker run -d -p 8080:8080 --name myapp aspnetapp

Try adding the following lines in docker file 尝试在docker文件中添加以下行

ENV ASPNETCORE_URLS http://+:80 
EXPOSE 80 

Reference: https://www.sep.com/sep-blog/2017/02/20/hosting-asp-net-core-docker/ 参考: https : //www.sep.com/sep-blog/2017/02/20/hosting-asp-net-core-docker/

我的容器化应用需要侦听/绑定到0.0.0.0,而不是127.0.0.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows docker 容器无法 ping 主机 - Windows docker container cannot ping host 企业代理后面的Windows 7上的Docker VM主机无法联系代理或更广泛的Internet - Docker VM host on Windows 7 behind corporate proxy cannot contact proxy or wider internet Docker:无法将 Docker 容器端口路由到主机 - Docker: cannot route docker container port to host Docker:在 Windows 主机上挂载卷 - Windows Container - Docker: Mount volume on Windows host - Windows Container 带Docker的Windows容器:无法从主机到达容器中的httpd(Win2016 TP5) - Windows Container with Docker: Cannot reach httpd in container from host (Win2016 TP5) Windows主机中docker windows容器的真实位置? - Real location of docker windows container in a windows host? 无法在Mac OS X主机上的Windows 10 VirtualBox VM中运行基于docker的Windows容器 - Cannot run docker based Windows container in Windows 10 VirtualBox VM on Mac OS X host Mac主机上的Docker-machine的容器联系人应用程序 - Docker-machine's container contact application on Mac host 无法在Windows上使用Docker停止容器 - Cannot stop container with docker on windows Windows的Docker Toolbox,容器在主机上不可用 - Docker Toolbox for Windows, Container is not accesible on the host
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM