Docker container cannot connect to linked containers services
<p>I'm using Docker version 1.9.1 build a34a1d5 on an Ubuntu 14.04 server host and I have 4 containers: redis (based on alpine linux 3.2), mongodb (based on alpine linux 3.2), postgres (based on ubuntu 14.04) and the one that will run the application that connects to these other containers (based on alpine linux 3.2). All of the db containers expose their corresponding ports in the Dockerfile.</p>

<p>I did the modifications on the database containers so their services don't bind to the localhost IP but to all addresses. This way I would be able to connect to all of them from the app container.
For the sake of testing, I first ran the database containers and then the app one with a command like the following:</p>

<pre><code>docker run --rm --name app_container --link mongodb_container --link redis_container --link postgres_container  -t localhost:5000/app_image
</code></pre>

<p>I enter the terminal of the app container and I verify that its /etc/hosts file contains the IP and names of the other containers. Then I am able to ping all the db containers. But I cannot connect to their ports to any of the db containers.</p>

<p>A simple: <code>telnet mongodb_container 27017</code> simply sits and waits forever, and the same happens if I try to connect to the other db containers. If I run the application, it also complains that it cannot connect to the specified db services.</p>

<p><strong>Important note:</strong> I am able to telnet the corresponding ports of all the db containers from the host.</p>

<p>What might be happening?</p>

<p><strong>EDIT:</strong> I'll include the run commands for the db containers:</p>

<pre><code>docker run --rm --name mongodb_container -t localhost:5000/mongodb_image
docker run --rm --name redis_container -t localhost:5000/redis_image
docker run --rm --name postgres_container -t localhost:5000/postgres_image
</code></pre>