从外部连接到在 docker 容器内运行的服务 [英] Connect to a Service running inside a docker container from outside

查看:104
本文介绍了从外部连接到在 docker 容器内运行的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 docker 容器(本地机器)中运行的服务.我可以在 Ambari 服务配置中看到服务 URL.

I have a service running in a docker container (local machine). I can see the service URL in the Ambari service config.

现在我想使用本地开发环境连接到该服务.

Now I want to connect to that service using my local development environment.

我发现我可以在容器内连接到该 URL,但是当我在本地外部使用该 URL 时,连接被拒绝.

I found I can connect to that within the container but when I use that URL outside in my local I get connection refused.

Cause: org.apache.http.conn.HttpHostConnectException: Connect to
xx.xx.xx.com:12008 [xx.xx.xx.com/195.169.98.101] failed: Connection refused

如何从外部连接到容器内运行的服务?
在我的例子中,代码在我的本地机器上执行.

How to connect to a service running inside a container from outside?
In my case code execute in my local machine.

推荐答案

如果您的容器已将其端口映射到 VM 12008 端口,则您需要确保在 VirtualBox 连接设置中已转发端口 12008,正如我所提到的在如何将mysql工作台连接到在docker内部运行mysql?"

If your container has mapped its port on the VM 12008 port, you would need to make sure you have port forwarded 12008 in your VirtualBox connection settings, as I mention in "How to connect mysql workbench to running mysql inside docker?"

VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port12008 ,tcp,,12008,,12008"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port12008 ,udp,,12008,,12008"

这篇关于从外部连接到在 docker 容器内运行的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆