PHP CURL无法在2个Docker站点之间进行连接

I am having an issue with two docker sites, site1.example.com and api.example.com. Both sites are hosted on my local machine via docker. I am trying to make a request to api.example.com via curl, like so:

$curl_handle=curl_init();
  curl_setopt($curl_handle,CURLOPT_URL,'http://api.example.com');
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,1000);
  curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl_handle, CURLOPT_HEADER, 1);
  curl_setopt($curl_handler, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curl_handle, CURLOPT_PROXY, true);
  curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
  curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
  $result = curl_exec($curl_handle);
  if($result === false) {
     $error = curl_error($curl_handle);
     print_r($error);
  }
  print_r($result);
  curl_close($curl_handle);

Here is what happens:

  1. If I turn-off CURLOPT_PROXY I get a connection refused error.
  2. I am getting a result = false with proxy on, except it gives no error message
  3. This is my docker logs:

[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Rebuilt URL to: http://api.example.local/?is_deleted=0"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "*   Trying 0.0.0.1..."
172.xx.x.x -  27/Nov/2018:18:23:03 +0000 "GET /index.php" 200
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* TCP_NODELAY set"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Immediate connect fail for 0.0.0.1: Invalid argument"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Closing connection 0"

But the same code and work fine on production. I am on php:7.2-fpm Any idea what is wrong with using curl from docker?