title: Localhost connection refused in Docker development environment
body: <p>I use Docker for my PHP development environment, and I set up my images with Docker Compose this way:</p>
  
  <pre><code>myapp:
      build: myapp/
      volumes:
          - ./myapp:/var/www/myapp
  
  php:
      build: php-fpm/
      expose:
          - 9000:9000
      links:
          - elasticsearch
      volumes_from:
          - myapp
      extra_hosts:
          # Maybe the problem is related to this line
          - "myapp.localhost.com:127.0.0.1"
  
  nginx:
      build: nginx/
      ports:
          - 80:80
      links:
          - php
      volumes_from:
          - myapp
  
  elasticsearch:
      image: elasticsearch:1.7
      ports:
          - 9200:9200
  </code></pre>
  
  <p>Nginx is configured (in its Docker file) with a virtual host named <code>myapp.localhost.com</code> (<code>server_name</code> parameter) and that points to the <code>/var/www/myapp</code> folder.</p>
  
  <p>All this works fine.</p>
  
  <p>But here is my problem: my web app is calling itself via the <code>myapp.localhost.com</code> URL with cURL (in the PHP code), which can be more easily reproduced by running this command:</p>
  
  <pre><code>docker-compose run php curl http://myapp.localhost.com
  </code></pre>
  
  <p>The cURL response is the following:</p>
  
  <blockquote>
    <p>cURL error 7: Failed to connect to myapp.localhost.com port 80: Connection refused</p>
  </blockquote>
  
  <p>Do you have any idea on how I can call the app URL? Is there something I missed in my <code>docker-compose.yml</code> file?</p>