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

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

问题描述

使用 ubuntu tusty,有一个在远程机器上运行的服务,我可以通过来自 localhost:9999 的 ssh 隧道通过端口转发进行访问.

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

遵循 this,parag.2 但没有感知到的交流,即使是在做的时候<代码>nc -luv 主机 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 - 测试连接是否正常的快速方法是什么?最好通过 bash.

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

谢谢.

推荐答案

我认为您可以通过将 --net=host 添加到您的 docker run 来实现.但也请参见这个问题:将主机端口转发到 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天全站免登陆