title: Curl connection refused between applications on Docker container
body: <p>I have a website (ZF1) and an API (Laravel) running on the same Docker (Laradock) container. I can access each separately through a browser, but when I make a cURL request from the website to the application, I get a null response and the header returns 0. If I output the cURL errors, then I get this:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, '[API_ENDPOINT]');
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_close ($ch);
  
  echo curl_strerror(curl_errno($ch));
  
  (7) Failed to connect to [API_HOST] port 80: Connection refused
  </code></pre>
  
  <p>However, if I make a cURL request to <a href="https://www.google.com" rel="nofollow noreferrer">https://www.google.com</a> from the application, then it returns a result. I also tried using file_get_contents(), but I received no response and the following warning:</p>
  
  <pre><code>[Thu May 18 21:41:33.828737 2017] [proxy_fcgi:error] [pid 949:tid 139999802541824] [client 172.20.0.1:49652] AH01071: Got error 'PHP message: PHP Warning:  file_get_contents
  ([API_ENDPOINT]): failed to open stream: Connection refused in /var/www/projects/[APPLICATION_PATH]/[CONTROLLER].php on line 2367\n', referer: [WEBSITE_HOST]/[URI]
  </code></pre>
  
  <p>I also SSHed into the Apache2 container and was able to make a successful cURL call to the API_ENDPOINT and get the expected data back. I then tried using wget to get the header info and received the following:</p>
  
  <pre><code>root@cd3a4177dcfa:/var/log/apache2# wget --header="Host: http://subdomain.example.dev/api/calendarevents" -Os http://localhost
  --2017-05-19 07:28:15--  http://localhost/
  Resolving localhost (localhost)... ::1, 127.0.0.1
  Connecting to localhost (localhost)|::1|:80... connected.
  HTTP request sent, awaiting response... No data received.
  Retrying.
  
  --2017-05-19 07:28:16--  (try: 2)  http://localhost/
  Connecting to localhost (localhost)|::1|:80... connected.
  HTTP request sent, awaiting response... No data received.
  Retrying.
  </code></pre>
  
  <p>In case it is an Apache2 issue, here is my API VirtualHost:</p>
  
  <pre><code>Listen 80
  &lt;VirtualHost *:80&gt;
    ServerName subdomain.example.dev
    DocumentRoot /var/www/projects/[API_PROJECT]/public/
    CustomLog /var/log/apache2/[API_HOST]-access.log combined
    ErrorLog /var/log/apache2/[API_HOST]-error.log
    Options Indexes FollowSymLinks
  
    &lt;Directory "/var/www/projects/[API_PROJECT]/public/"&gt;
        Options FollowSymLinks
        AllowOverride All
        Require all Granted
    &lt;/Directory&gt;
  
    # set environment
    #SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 // Did not notice a difference in behavior when enabled
    #CGIPassAuth on // Sites stopped loading when enabled
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>And Website VirtualHost:</p>
  
  <pre><code>Listen 80
  &lt;VirtualHost *:80&gt;
    ServerName [WEBSITE_HOST]
    DocumentRoot /var/www/projects/[WEBSITE_PROJECT]
    ErrorLog /var/log/apache2/[WEBSITE_HOST]-error.log
    Options Indexes FollowSymLinks
  
    &lt;Directory "/var/www/projects/[WEBSITE_PROJECT]/repo"&gt;
      Options FollowSymLinks
      AllowOverride All
      Require all Granted
    &lt;/Directory&gt;
  
    # set environment
    SetEnv APPLICATION_ENV development
    SetEnv APPLICATION_LOGGING false
    #SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 // Did not notice a difference in behavior when enabled
    #CGIPassAuth on // Sites stopped loading when enabled
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>This is the Docker info (Windows 10/Hyper V/Docker Version 17.03.1-ce-win12 (12058) Channel: stable)</p>
  
  <pre><code>Containers: 9
   Running: 5
   Paused: 0
   Stopped: 4
  Images: 233
  Server Version: 17.03.1-ce
  Storage Driver: overlay2
   Backing Filesystem: extfs
   Supports d_type: true
   Native Overlay Diff: true
  Logging Driver: json-file
  Cgroup Driver: cgroupfs
  Plugins:
   Volume: local
   Network: bridge host ipvlan macvlan null overlay
  Swarm: inactive
  Runtimes: runc
  Default Runtime: runc
  Init Binary: docker-init
  containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
  runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
  init version: 949e6fa
  Security Options:
   seccomp
    Profile: default
  Kernel Version: 4.9.27-moby
  Operating System: Alpine Linux v3.5
  OSType: linux
  Architecture: x86_64
  CPUs: 2
  Total Memory: 3.837 GiB
  Name: moby
  ID: PE42:IS45:4OO6:JMEQ:NWNB:NQDF:RPEL:JPHJ:L6OP:A5SL:IDP3:F7SV
  Docker Root Dir: /var/lib/docker
  Debug Mode (client): false
  Debug Mode (server): true
   File Descriptors: 86
   Goroutines: 74
   System Time: 2017-05-19T04:52:50.5943959Z
   EventsListeners: 0
  Registry: https://index.docker.io/v1/
  Experimental: true
  Insecure Registries:
   127.0.0.0/8
  Live Restore Enabled: false
  </code></pre>
  
  <p>And these are the containers that I am currently running:</p>
  
  <pre><code>CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                                      NAMES
  cd3a4177dcfa        laradock_apache2     "/opt/docker/bin/e..."   8 hours ago         Up 8 hours          0.0.0.0:80-&gt;80/tcp, 0.0.0.0:443-&gt;443/tcp   laradock_apache2_1
  8ef66cb80a2e        laradock_php-fpm     "docker-php-entryp..."   8 hours ago         Up 8 hours          9000/tcp                                   laradock_php-fpm_1
  988eff458036        laradock_workspace   "/sbin/my_init"          8 hours ago         Up 8 hours          0.0.0.0:2222-&gt;22/tcp                       laradock_workspace_1
  8be5253e8622        laradock_redis       "docker-entrypoint..."   8 hours ago         Up 8 hours          0.0.0.0:6379-&gt;6379/tcp                     laradock_redis_1
  aa6d8d6ae950        laradock_mysql       "docker-entrypoint..."   8 hours ago         Up 8 hours          0.0.0.0:3306-&gt;3306/tcp                     laradock_mysql_1
  </code></pre>
  
  <p>I am not sure what is causing the connection to be refused between the two sites on the same container. I checked my php.ini and both curl and allow_url_fopen = on were enabled. I am able access the API_ENDPOINT directly through both browser and CLI cURL and get the expected results. My best guesses at this point are some sort of port conflict, an authorization header being blocked, Apache2 configuration, or some sort of odd Docker/Laradock issue. I also thought it might of been a conflict between Apache2 and PHP-FPM, but the solutions <a href="https://stackoverflow.com/questions/17018586/apache-2-4-php-fpm-and-authorization-headers">detailed here</a> didn't seem to work for me.</p>
  
  <p>Thank you in advanced for any assistance that you can provide.</p>