从外部连接到在 docker 容器内运行的服务

编程入门 行业动态 更新时间:2024-10-27 23:20:13
本文介绍了从外部连接到在 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:12008 [xx.xx.xx/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 容器内运行的服务

本文发布于:2023-10-14 12:25:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1491050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   容器内   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!