title: Docker curl: (7) Failed to connect to localhost port 80: Connection refused
body: <p>I execute from native host and </p>
  
  <blockquote>
    <p>$ curl localhost</p>
    
    <p>or </p>
    
    <p>$ curl </p>
    
    <p><a href="http://usuariointerno:governance@beneficiarios.dev/app_dev.php/actividad" rel="nofollow noreferrer">http://usuariointerno:governance@beneficiarios.dev/app_dev.php/actividad</a></p>
    
    <p>and response its ok.</p>
  </blockquote>
  
  <p>if execute from container name "php" and : </p>
  
  <blockquote>
    <p>$ curl localhost --ipv4</p>
    
    <p>Failed to connect to localhost port 80: Connection refused</p>
  </blockquote>
  
  <p>or </p>
  
  <blockquote>
    <p>$curl
    <a href="http://usuariointerno:governance@beneficiarios.dev/app_dev.php/actividad" rel="nofollow noreferrer">http://usuariointerno:governance@beneficiarios.dev/app_dev.php/actividad</a></p>
    
    <p>curl: (7)Failed to connect to localhost port 80: Connection refused</p>
  </blockquote>
  
  <p>When connect from docker container faill, if connect outside of docker container its OK, What its the problem?</p>
  
  <p>docker-compose:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>version: '2'
  services:
    php:
      container_name: php
      build: ./php
      volumes:
        - ./www/:/var/www/html/
        - ./php/.bashrc:/root/.bashrc
        - ./php/.gitconfig:/root/.gitconfig
      depends_on:
        - postgres
        - mysql
  
    nginx:
      container_name: nginx
      image: nginx
      ports:
        - 80:80
      volumes:
        - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
        - ./www/:/var/www/html/
        - ./logs:/var/log/nginx
      depends_on:
        - php
      
    postgres:
      container_name: postgres
      image: postgres:9.5.5
      volumes:
        - ./data/postgresql:/var/lib/postgresql/data
        - ./postgres/dumps:/dumps
      environment: 
       - POSTGRES_PASSWORD=0000
       - POSTGRES_USER=postgres
  
    mysql:
      container_name: mysql
      image: mysql:5.7.16
      volumes:
        - ./data/mysql:/var/lib/mysql
      environment: 
        - MYSQL_ROOT_PASSWORD=0000</code></pre>
  </div>
  </div>
  </p>
  
  <p>nginx.conf</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>server {
      listen 80;
      server_name beneficiarios.dev;
      root /var/www/html/beneficiarios/web;
      
      
      add_header Access-Control-Allow-Origin *;
  
      location / { try_files $uri /app.php$is_args$args;}
     
     #dev
      location ~ ^/(app_dev|config)\.php(/|$) {
          add_header Access-Control-Allow-Origin *;
          fastcgi_buffers 16 256k; 
          fastcgi_buffer_size 256k;
          fastcgi_pass php:9000;
          fastcgi_split_path_info ^(.+\.php)(/.*)$;
          include fastcgi_params;
         
          fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT $realpath_root;
      }
  
      location ~ ^/app\.php(/|$) {
          fastcgi_buffers 16 256k; 
          fastcgi_buffer_size 256k;
          fastcgi_pass php:9000;
          fastcgi_split_path_info ^(.+\.php)(/.*)$;
          include fastcgi_params;
          
          fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT $realpath_root;
         
          internal;
      }
  
      location ~ \.php$ {
        return 404;
      }
  
      error_log /var/log/nginx/project_error.log;
      access_log /var/log/nginx/project_access.log;
  }</code></pre>
  </div>
  </div>
  </p>