简体   繁体   English

从Docker容器向主机超时发出卷曲请求

[英]Curl request from docker container to host timeout

Im encountering an issue with docker which I believe is due to a gap in my knowledge about docker networking. 我遇到docker问题,我认为这是由于我对docker网络的了解不足。

I have a docker image running nginx and php. 我有一个运行nginx和php的docker镜像。 The necessary ports are exposed. 必要的端口已暴露。 Here is a simplified command I have been using to run the image. 这是我用来运行映像的简化命令。

docker run --name php-app -p 80:80 php-app

The issue is that for installation setup, the php application curls to itself using the host machines public IP. 问题在于,对于安装设置,php应用程序使用主机的公共IP自行卷曲。

As an example, curl http://105.15.25.120/phpsetup.php?setup 例如, curl http://105.15.25.120/phpsetup.php?setup

This IP seems to be unreachable from inside the container, as curl times out 由于卷曲超时,似乎无法从容器内部访问此IP

curl -vvv 105.15.25.120
About to connect() to 105.15.25.120 port 80 (#0)
Trying 105.15.25.120...
Connection timed out
Failed connect to 105.15.25.120:80; Connection timed out
Closing connection 0
curl: (7) Failed connect to 105.15.25.120:80; Connection timed out

I can successfully curl to other IP's from inside the container, just not the host's. 我可以从容器内部成功卷曲到其他IP,而不仅仅是主机的。

Using curl from the host machine works fine, and does not result in any strange behaviour. 从主机使用curl可以正常工作,并且不会导致任何奇怪的行为。

For simplicity and testing, I have reproduced the behaviour with the official nginx image, to help conclude that it's not an issue with my own image. 为了简单起见和测试,我使用官方的nginx图像重现了该行为,以帮助得出结论,这与我自己的图像无关。

docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -p 80:80

From my research, it seems to be a routing issue? 从我的研究看来,这似乎是一个路由问题? Not sure. 不确定。

the container should not curl the host. 容器不应使主机卷曲。 it should curl itself, as it is hosting the content you wish to curl. 它应该自动卷曲,因为它承载了您希望卷曲的内容。

curl http://127.0.0.1/phpsetup.php?setup

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM