title: Forward host port to docker container
body: <p>Is it possible to have a Docker container access ports opened by the host? Concretely I have  MongoDB and  RabbitMQ running on the host and I'd like to run a process in a Docker container to listen to the queue and (optionally) write to the database.</p>
  <p>I know I can forward a port from the container to the host (via the -p option) and have a connection to the outside world (i.e. internet) from within the Docker container but I'd like to not expose the RabbitMQ and MongoDB ports from the host to the outside world.</p>
  <p>EDIT: some clarification:</p>
  <pre><code>Starting Nmap 5.21 ( http://nmap.org ) at 2013-07-22 22:39 CEST
  Nmap scan report for localhost (127.0.0.1)
  Host is up (0.00027s latency).
  PORT     STATE SERVICE
  6311/tcp open  unknown
  
  joelkuiper@vps20528 ~ % docker run -i -t base /bin/bash
  root@f043b4b235a7:/# apt-get install nmap
  root@f043b4b235a7:/# nmap 172.16.42.1 -p 6311 # IP found via docker inspect -&gt; gateway
  
  Starting Nmap 6.00 ( http://nmap.org ) at 2013-07-22 20:43 UTC
  Nmap scan report for 172.16.42.1
  Host is up (0.000060s latency).
  PORT     STATE    SERVICE
  6311/tcp filtered unknown
  MAC Address: E2:69:9C:11:42:65 (Unknown)
  
  Nmap done: 1 IP address (1 host up) scanned in 13.31 seconds
  </code></pre>
  <p>I had to do this trick to get any internet connection within the container: <a href="https://stackoverflow.com/questions/17394241/my-firewall-is-blocking-network-connections-from-the-docker-container-to-outside">My firewall is blocking network connections from the docker container to outside</a></p>
  <p><strong>EDIT</strong>: Eventually I went with creating a custom bridge using <a href="https://github.com/jpetazzo/pipework" rel="nofollow noreferrer">pipework</a> and having the services listen on the bridge IP's. I went with this approach instead of having MongoDB and RabbitMQ listen on the docker bridge because it gives more flexibility.</p>