I have these two containers, say backend
(CentOs) and mongo
. What I would like to have is that from within the backend
container I can connect to the mongo database as if it was running locally, $> mongo localhost:27017
Anyway, as far as I understand all this, you can map the port localhost:27017 to mongo:27017 like this
$backend> ssh -L 27017:mongo:27017 root@mongo
However, if I do this I have to provide the root password and after that it logs me into the mongo
container and no port forwarding is happening
Background: I want to do this because I'm running a Java program which connects to a Mongo database on localhost and I cannot change that.
I found the correct SSH port forwarding command
Normally the idea with this command is that you map a non-public port - through a public server to you own server/compute.
Because the
public server
andthird server
are the same computer/container you have to uselocalhost
:)