Docker - OS X转发本地主机22端口到容器2022端口 [英] Docker - OS X forward localhost 22 port to container 2022 port

查看:172
本文介绍了Docker - OS X转发本地主机22端口到容器2022端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OSX上使用Docker。



我有一个容器,打开 ssh 守护进程,收听端口 22



虚拟机设置为转发端口的所有流量 2022 到该容器的 22 端口。



我想设置我的本地主机将所有 2022 流量转发到机器 2022 端口。



我的机器运行在 192.168.99.100



我已经转发了本地端口8080上的所有HTTP流量到机器使用Apache虚拟主机配置和代理。



什么是正确的方法来做同样的ssh?



我认为它涉及SSH隧道,如 here 但是我不明白我如何设置我的本地主机将始终将ssh连接从 localhost:2022 转发到 192。 168.99.100:2022



p.s。我知道docker容器不应该安装SSH,但是我需要它来进行测试。

解决方案


现在我想连接我的本地主机:2022到机器:2022


然后你需要你的boot2docker VM(由docker-machine创建)将端口2022端口转发到您的MacOS主机。

请参见 docker nginx容器未收到外部请求,连接拒绝为例。

  VBoxManage controlvmdefaultnatpf1tcp-port2022,tcp ,, 2022,,2022
VBoxManage controlvm默认natpf1udp-port2022,udp ,, 2022,,2022

注意:这不是与ssh具体相关,它仅与您使用VM作为Linux主机的事实相关,并且已将映射到其端口2022.

该端口将从您的实际MacOS localhost可见只有你端口转发。


I'm using Docker on my Mac OSX.

I have a container with an open ssh daemon, listening to port 22.

The virtual machine is set to forward all traffic of port 2022 of the machine to this container 22 port.

I want to set my localhost to forward all 2022 traffic to the machine 2022 port.

My machine runs at 192.168.99.100

I already forwarded all the HTTP traffic at localhost port 8080 to the machine using Apache virtual host configuration and Proxy.

What is the right way to do the same for ssh?

I think it involve SSH Tunnelling as mentioned here but I don't understand how I can set that my localhost will always forward ssh connections from localhost:2022 to 192.168.99.100:2022

p.s. I know docker container should not have SSH installed, but I need it for testing proposes.

解决方案

now I want to connect between my localhost:2022 to the machine:2022

Then you need your boot2docker VM (created by docker-machine) to port-forward the port 2022 to your MacOS host.
See "docker nginx container not receiving request from outside, connection refused" as an example.

VBoxManage controlvm "default" natpf1 "tcp-port2022,tcp,,2022,,2022"
VBoxManage controlvm "default" natpf1 "udp-port2022,udp,,2022,,2022"

Note: this is not releated to ssh specifically, it is only related to the fact that you are using a VM as a Linux host, and you have mapped something to its port 2022.
That port will be visible from your actual MacOS localhost only if you port-forward it.

这篇关于Docker - OS X转发本地主机22端口到容器2022端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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