[英]App within docker container cannot invoke service on same container
To start my docker container i use : 要启动我的docker容器,我使用:
docker run -p 5001:5001 -p 7777:7777 -i -t --entrypoint /bin/bash dc261bdea451
As can see I'm exposing two ports : 5001 & 7777 可以看出我暴露了两个端口:5001和7777
nodejs
is running on port 5001 & socko server on 7777. From the browser I can access these services directly via http://localhost:5001
& http://localhost:7777
. nodejs
正在nodejs
上的端口5001和socko服务器上运行。在浏览器中,我可以通过http://localhost:5001
& http://localhost:7777
直接访问这些服务。 The nodejs app running on port 5001 makes a call to the service running on port 7777 : 在端口5001上运行的nodejs应用程序调用在端口7777上运行的服务:
So by invoking http://localhost:5001
a call to http://localhost:7777
is made : 因此,通过调用
http://localhost:5001
可以调用http://localhost:7777
:
var request = require('request');
request("http://localhost:7777?param=param....
The issue is service running on port 7777 is not being invoked. 问题是没有调用端口7777上运行的服务。 I also tried :
我也尝试过:
var request = require('request');
request("http://127.0.0.1:7777?param=param....
but same result. 但结果相同。
This issue does not occur when I run the apps outside of docker container. 当我在docker容器外运行应用程序时,不会发生此问题。
Is there a config option I'm missing that allows two servers running on one docker container to communicate ? 是否有一个我缺少的配置选项允许在一个docker容器上运行的两个服务器进行通信?
Update : 更新:
Changing the hostname to IP address of machine docker container is running on reaches the endpoint. 将主机名更改为机器泊坞窗容器的IP地址正在运行到达端点。 So changing this works :
所以改变这种方式:
var request = require('request');
request("http://localhost:7777?param=param....
to 至
var request = require('request');
request("http://my.ip.address:7777?param=param....
But this is not a solution as it requires an update to the container after it's deployed. 但这不是一个解决方案,因为它需要在部署后更新容器。
-p
flag) to allow container internal communication. -p
标志)来允许容器内部通信。 This is only required when you want to connect from your host to the container. Anyway, to investigate the issue start a bash in your container to validate the service on port 7777 is reachable from within the container ( docker exec -it <container_id> bash
, telnet localhost 7777
). 无论如何,要调查此问题,请在容器中启动bash以验证端口7777上的服务是否可从容器内访问(
docker exec -it <container_id> bash
, telnet localhost 7777
)。 In case it is not listening you need to check that it is binding to the correct hostname. 如果它没有监听,你需要检查它是否绑定到正确的主机名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.