I would like to have my docker container on the remote to access my local
machine. This can be done by these two steps:
First, access host port from docker container using a special ip
Docker use docker0’s interface ip to access the remote host port , this ip
can be found using following command
ip addr show docker0 | grep -Po ‘inet \K[\d.]+’
In my case, the ip address 172.17.0.1
Ping this address from the docker container to test.
Now map a remote host port number to my local pc port number using ssh
command
ssh -R \*:3636:localhost:3636 -N ssr.dengnz.com -l fennng
After that, my docker container on remote linux should be able to access my
local port using 172.17.0.1:3636.
But it failed.
Then I figured out that the port 3636 is not really bind to *, it’s bind to
localhost only.
netstat -a | grep 3636
Why is that?
After some time of research, I found out that some sshd confire is needed
to bind to *.
sudo vim /etc/ssh/sshd_config
set GatewayPorts yes
It still doesn’t work, I need to reload the ssh config
/etc/init.d/sshd reload
if reload doesn’t work, restart can be helpful
/etc/init.d/sshd restart
Then magic happen.
Now I can access from my docker container on a remote linux VPS to my local
pc using 172.17.0.1:3636. Which is great, it open a new door for your to
debug remote docker container apps.