title: Failing to connect to localhost from inside a container Connection refused
body: <p>I'm currently testing an Ansible role using Molecule.
  Basically, Molecule launches a container that is Ansible compliant and runs the role on it.</p>
  
  <p>In order to test the container, Molecule also embed unit tests using Testinfra. The python unit tests are run from within the container so you can check the compliance of the role.</p>
  
  <p>As I'm working on an Nginx based role, one of the unit tests is simply issuing a <code>curl http://localhost:80</code></p>
  
  <p>I do get the below error message in response:</p>
  
  <blockquote>
    <p>curl: (7) Failed to connect to localhost port 80: Connection refused</p>
  </blockquote>
  
  <p>When I:</p>
  
  <ul>
  <li>launch a Vagrant machine</li>
  <li>apply the role with Ansible</li>
  <li>connect via <code>vagrant ssh</code>   </li>
  <li>issue a <code>curl http://localhost</code> command</li>
  </ul>
  
  <p>nginx answers correctly.</p>
  
  <p>Therefore, I believe that:</p>
  
  <ul>
  <li>the role is working properly and Nginx is installed correctly</li>
  <li>Docker has a different way to set-up the network. In a way, localhost and 127.0.0.1 <em>are not the same anymore</em>.</li>
  </ul>
  
  <p>My questions are the following:</p>
  
  <ol>
  <li>Am I correct?</li>
  <li>Can this difference be overcome so the curl would work?</li>
  </ol>