Docker - OS X forward localhost 22 port to container 2022 port

∥☆過路亽.° 提交于 2019-11-28 06:09:43

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/36385402/docker-os-x-forward-localhost-22-port-to-container-2022-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!