title: Docker: Connection from inside the container to localhost:port Refused
body: <p>I'm trying to insure the connection between the different containers and the localhost address (<strong>127.0.0.1</strong>) used with port <strong>8040</strong>.( My web application container run using this port.)</p>
  
  <pre><code> root@a70b20fbda00:~# curl -v http://127.0.0.1
   * Rebuilt URL to: http://127.0.0.1/
   * Hostname was NOT found in DNS cache
   *   Trying 127.0.0.1...
   * connect to 127.0.0.1 port 80 failed: Connection refused
   * Failed to connect to 127.0.0.1 port 80: Connection refused
   * Closing connection 0
   curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
  </code></pre>
  
  <p>This is what I get when I want to connect to localhost from inside the container</p>
  
  <pre><code>root@a70b20fbda00:~# curl -v http://127.0.0.1:8040
  * Rebuilt URL to: http://127.0.0.1:8040/
  * Hostname was NOT found in DNS cache
  *   Trying 127.0.0.1...
  * connect to 127.0.0.1 port 8040 failed: Connection refused
  * Failed to connect to 127.0.0.1 port 8040: Connection refused
  * Closing connection 0
  curl: (7) Failed to connect to 127.0.0.1 port 8040: Connection refused
  </code></pre>
  
  <p>About <strong>iptables</strong> in each container:</p>
  
  <pre><code> root@a70b20fbda00:~# iptables
   bash: iptables: command not found
  </code></pre>
  
  <p>Connection between the container is good </p>
  
  <pre><code>root@635114ca18b7:~# ping 172.17.0.1
  PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
  64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.061 ms
  64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.253 ms
  --- 172.17.0.1 ping statistics ---
  2 packets transmitted, 2 received, 0% packet loss, time 1002ms
  root@635114ca18b7:~# ping 127.0.0.1
  PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.080 ms
  64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.100 ms
  --- 127.0.0.1 ping statistics ---
  2 packets transmitted, 2 received, 0% packet loss, time 1001ms
  root@635114ca18b7:~# ping 172.17.0.3
  PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
  64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.149 ms
  64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.180 ms
  --- 172.17.0.3 ping statistics ---
  2 packets transmitted, 2 received, 0% packet loss, time 1001ms
  rtt min/avg/max/mdev = 0.149/0.164/0.180/0.020 ms
  </code></pre>
  
  <p>Ping the 127.0.0.1:8040 </p>
  
  <pre><code>root@635114ca18b7:~# ping 127.0.01:8040
  ping: unknown host 127.0.0.1:8040
  </code></pre>
  
  <p>What I need to do in this case?</p>
  
  <p>So the Global image that there is two containers ,<br></p>
  
  <ul>
  <li>The first container contains a <strong>tomcat server</strong> that deploy my <strong>web application</strong> and it turnes perfectly.<br></li>
  <li>The second is a container that need to connect to the web application 
  URL. <strong><a href="http://127.0.0.1:8040/my_app" rel="nofollow noreferrer">http://127.0.0.1:8040/my_app</a></strong></li>
  </ul>