从另一个码头集装箱的码头箱容器运行访问服务 [英] Access service running in docker container from inside another docker container
问题描述
目前,我正在Docker容器中运行一个node.js应用程序,该容器需要连接到在另一个容器中运行的camunda。
At the moment I'm running a node.js application inside a docker container which needs to connect to camunda, which runs in another container.
我使用以下命令启动容器
I start the containers with the following command
docker run -d --restart=always --name camunda -p 8000:8080 camunda/camunda-bpm-platform:tomcat-7.4.0
docker run -d --name app -p 3000:3000 app
这两个应用程序正在运行,我可以通过导航到我的主机的端口8000上的IP来访问camunda,并运行wget http:// localhost:8000 -q -O -
还返回camunda页面。当我使用 docker exec -it app sh
登录到我的应用程序容器,并键入 wget http:// localhost:8000 -q -O -
,我无法访问camunda。相反,我会收到以下错误:
Both applications are now running and I can access camunda by navigating to my host's IP on port 8000, and running wget http://localhost:8000 -q -O -
also returns the camunda page. When I login to my app container with docker exec -it app sh
and type wget http://localhost:8000 -q -O -
, I cannot access camunda. Instead I get the following error:
wget: can't connect to remote host (127.0.0.1): Connection refused
当我将应用程序容器链接到具有的camunda容器时 - link camunda:camunda
,并在我的应用程序容器中键入 wget http:// camunda:8000 -q -O -
,我收到以下错误:
When I link my app container to the camunda container with --link camunda:camunda
, and type wget http://camunda:8000 -q -O -
in my app container, I get the following error:
wget: can't connect to remote host (172.17.0.4): Connection refused`
我看过此选项,所以我启动了我的应用程序容器,其中包含 - add-host camunda:my_hosts_ip
并再次尝试了wget,从而导致:
I've seen this option, so I started my app container with --add-host camunda:my_hosts_ip
and tried wget again, resulting in:
wget: can't connect to remote host (149.210.227.191): Operation timed out
运行 wget http://149.210.227.191:5001 -q -O -
在我的主机上,但我得到一个立即正确回复
When running wget http://149.210.227.191:5001 -q -O -
on my host machine however, I get a correct response immediately.
理想情况下,我想启动我的应用程序容器,而不需要以任何方式提供外部IP,让应用程序容器只需通过localhost使用camunda服务或者将camunda容器连接到我的应用程序容器。实现这个最简单的方法是什么?
Ideally I would like to just start my app container without the need to supply the external IP in any way, and let the app container just use the camunda service via the localhost or by linking the camunda container tot my app container. What would be the easiest way to achieve this?
推荐答案
使用 - link camunda:camunda
选项。然后你可以通过 http:// camunda:8080 / ...
访问camunda。链接选项使用camunda容器的IP地址向应用程序容器的 / etc / hosts
文件添加一个条目。这也意味着如果您重新启动camunda容器,则必须重新启动应用程序容器。
Use the --link camunda:camunda
option for your app container. Then you can access camunda via http://camunda:8080/...
. The link option adds a entry to the /etc/hosts
file of the app container with the IP address of the camunda container. This also means you have to restart your app container if you restart the camunda container.
这篇关于从另一个码头集装箱的码头箱容器运行访问服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!