Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker SSH forwarding - bind: Address not available

I have a Docker container, which I would like to be able to interact with a database trough a SSH tunnel.

My Docker image is built on an alpine image and in the Dockerfile I have installed openssh-client and exposed port 27017

When I spin up my Docker image and try to forward the ports with:

ssh -i /.ssh/ssh_key user@remote_ip -L 27017:localhost:27017 -Nf

I get an error:

bind: Address not available

It is not a problem to ssh into the remote server, but I am not able to forward the ports.

Thanks

like image 834
ChrKong Avatar asked Sep 24 '18 12:09

ChrKong


1 Answers

I manage to create a ssh tunnel from a docker-compose using this entrypoint:

ssh -4 -i /.ssh/ssh_key -NL *:27017:0.0.0.0:27017 user@remote_ip


and then i was able to use the ssh tunnel from an another container by using the network created with the docker-compose

docker run --network=tunnel_default image nmap -p 27027 service_name


tunnel_default is the name of the network

image is a docker image where nmap is installed (it allows you to check open ports)

service_name is the name i gave to the service inside the docker-compose

like image 66
ssh_tunnel Avatar answered Sep 30 '22 17:09

ssh_tunnel