title: SSH port forwarding in Docker
body: <p>I have these two containers, say <code>backend</code> (CentOs) and <code>mongo</code>. What I would like to have is that from within the <code>backend</code> container I can connect to the mongo database as if it was running locally, <code>$&gt; mongo localhost:27017</code></p>
  
  <p>Anyway, as far as I understand all this, you can map the port localhost:27017 to mongo:27017 like this</p>
  
  <pre><code>$backend&gt; ssh -L 27017:mongo:27017 root@mongo
  </code></pre>
  
  <p>However, if I do this I have to provide the root password and after that it logs me into the <code>mongo</code> container and no port forwarding is happening</p>
  
  <p>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.</p>