Error using cURL POST service using Doker container: 'cURL error 7: Failed to connect to port 80: Connection refused' What could be happening?

Viewed 33

My Docker has 1 container that contains several projects that communicate with each other using services via curl or GuzzleHttp / Client.

What I have as an example:

1 - Project http://app1.local can be accessed normally in the browser.

2 - Project http://app1.local makes a POST to http://app2.local Returns: cURL error 7: Failed to connect to app2.com port 80: Connection refused

3 - If I make the same request via POSTMAN, it works normally.

4 - My etc/host already contains the information:

127.0.0.1 app1.local 
127.0.0.1 app2.local

5 - My machine is Windows.

My docker composer

version: '2'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./code:/code
      - ./conf/app.conf:/etc/nginx/conf.d/default.conf
      - ./conf/nginx.crt:/etc/nginx/ssl/nginx.crt
      - ./conf/nginx.key:/etc/nginx/ssl/nginx.key
      - ./conf/dhparam.pem:/etc/nginx/ssl/dhparam.pem
      - ./conf/hosts:/etc/hosts
    links:
      - php
      - redis
      - db
  php:
    build: ./docker/php/
    volumes:
      - ./code:/code
      # - ./conf/php.ini:/usr/local/etc/php/php.ini
      - ./conf/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./conf/hosts:/etc/hosts
    links:
      - db
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
  db:
    image: mysql:5.7.22
    environment:
      - MYSQL_ROOT_PASSWORD=app
    ports:
      - "3306:3306"
    volumes:
      - ./conf/my.cnf:/etc/mysql/my.cnf

my POST call in PHP

$response = $this->client->request('POST', 'http://app2.local/api', [                
    'json' => [
        'email'    => $user->email,
        'password' => $user->password,
    ]
]);

My nginx.conf

server {
    listen  80 default_server;
    listen  [::]:80 default_server;

    index index.php index.html;
    server_name ~(?<app>.+)\.local$;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.$app.log;

    root /code/$app/public;

    location / {
       try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_read_timeout 10000;
    }
}
0 Answers
Related