2

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.

Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
  • If you doing this in Docker, have you tried using the --port flag to map 2022:2022? – ryekayo Apr 03 '16 at 12:30
  • In run command I used -p 2022:22 which connect between the machine (192.168.99.100:2022) to the container (container:22), now I want to connect between my localhost:2022 to the machine:2022 – Asaf Nevo Apr 03 '16 at 12:31
  • Ok, well what your doing in this instance is your publishing the container's port (2022) to the machine's port (22). Now if i understand this correctly, you should be using -p 2022:2022 – ryekayo Apr 03 '16 at 12:33

1 Answers1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you guide on where to find info about it? – Asaf Nevo Apr 03 '16 at 12:37
  • @AsafNevo I was still editing the answer at the time of your comment. I have added the relevant VBoxManage commands. – VonC Apr 03 '16 at 12:39
  • What do you mean by `That port will be visible from your actual MacOS localhost only if you port-forward it.` How should I port forward it – Asaf Nevo Apr 03 '16 at 13:52
  • @AsafNevo "How should I port forward it?": by typing the two commands I mention in the answer: the Linux VM that you are using needs to forward those ports to your actual MacOS host in order for said MacOS host to access 2022 with "localhost". – VonC Apr 03 '16 at 13:53