#StackBounty: #docker #ssl #curl #drupal Cannot get or post data from API with Drupal app served with Docker Compose

Bounty: 100

I have some apps running locally via. docker for development. 2 days ago they were working fine, but yesterday a bug came out. I use curl to get data from an API served on a remote host, and this stopped working yesterday, and is still not working. The curl command to get data is

$ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, getenv('DATABASE_URL'));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_VERBOSE, 0);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
      curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));  
      $output = curl_exec($ch)
      return $output;

which now returns an error saying I don’t have permission to use the API. This of course doesn’t tell you much, so let me get into some details about the apps.

They are drupal 8 apps, served by docker (and docker-compose). I have checked that they have access to the internet (more about this later), and the app’s connection to a local mysql server is working fine. I have tried to restart docker, rebuilding the containers, and such standard hacks, but nothing seems to fix it. I have a laravel app served locally with docker aswell, using the same API, and this app can retrieve and post data from the API, so the problem seems to have to do with the drupal code. Althought this might not be true, since I have tried to use older versions before this started happening, and the same error still occurs. This leads me to think that it could also be an ssl certificate error, but I have not found a way to test this.

Some strange things I have noticed:

  • The production version of the drupal app (with identical code) served on a remote server we control is working, and it is using the same API (Ubuntu is run both locally and on the remote server).
  • When I turn on my computer, the the apps (both laravel and druppal) does not have internet, and I have to stop and start (with docker-compose down and up) them for them to get internet.

I know this is not at all enough to find out exactly what is wrong here, but I am hoping that someone might have seen some of these problems before, and give a hint to fix something.

As always, if you need any specific code or explanation of the app , just ask, and I’ll happily supply it.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.