Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...