从Docker容器访问主机的ssh隧道 [英] access host's ssh tunnel from docker container

查看:409
本文介绍了从Docker容器访问主机的ssh隧道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ubuntu tusty,在远程计算机上运行了一项服务,我可以通过SSH隧道通过端口转发从 localhost:9999 访问该服务。

Using ubuntu tusty, there is a service running on a remote machine, that I can access via port forwarding through an ssh tunnel from localhost:9999.

我正在运行一个Docker容器。我需要通过主机的隧道从容器内部访问该远程服务。

I have a docker container running. I need to access that remote service via the host's tunnel, from within the container.

我尝试使用 -L从容器到主机的隧道9000:host-ip:9999 ,然后从容器内部通过 127.0.0.1:9000 访问服务失败。要检查端口映射是否打开,我尝试了

nc -luv -p 9999#在主机
nc -luv -p 9000#在容器

I tried tunneling from the container to the host with -L 9000:host-ip:9999 , then accessing the service through 127.0.0.1:9000 from within the container fails to connect. To check wether the port mapping was on, I tried nc -luv -p 9999 # at host nc -luv -p 9000 # at container

跟随此,parag。 2 ,但即使在执行

nc -luv host-ip -p 9000
时,也没有感知到的通信容器

following this, parag. 2 but there was no perceived communication, even when doing nc -luv host-ip -p 9000 at the container

我还尝试通过 docker run -p 9999:9000 映射端口,但这报告了绑定失败,因为主机端口已在使用(大概是从主机隧道到远程计算机)。

I also tried mapping the ports via docker run -p 9999:9000 , but this reports that the bind failed because the host port is already in use (from the host tunnel to the remote machine, presumably).

所以我的问题是

1-如何实现连接?我是否需要设置一条通往主机的ssh隧道,还是可以仅通过docker端口映射来实现?

1 - How will I achieve the connection? Do I need to setup an ssh tunnel to the host, or can this be achieved with the docker port mapping alone?

2-测试连接的快速方法是什么起来了吗

2 - What's a quick way to test that the connection is up? Via bash, preferably.

谢谢。

推荐答案

我认为你可以通过在您的docker run中添加-net = host 来实现。但也请参见以下问题:将主机端口转发到Docker容器

I think you can do it by adding --net=host to your docker run. But see also this question: Forward host port to docker container

这篇关于从Docker容器访问主机的ssh隧道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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