1

I am using Docker for Windows to host the Laravel instance

I have Laravel running on Docker (running on http://localhost:8080). I have an API service on a http://api.mywebsite.test which is on my computer - not in a docker.

I'm trying to CURL the REST API from the docker website. It doesn't respond and I have no clue why.

When i curl from bash, it works correctly. Example :

curl --location --request POST 'http://oauth.mysite.test/server.php?grant_type=client_credentials' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=client_credentials'

From my browser it works as well.

But from my php script, file_get_contents for example returns an error :

ErrorException: file_get_contents(http://oauth.mysite.test/server.php): Failed to open stream: HTTP request failed!

Using Guzzle just loops forever and just crashes my Docker which I need to then restart.

StarNab
  • 31
  • 5
  • 1
    I cannot imagine curl would work from the docker container, probably you now connect from host to host (itself). What you want to do to connect from inside a container to the host is using `host.docker.internal`. – online Thomas Aug 17 '21 at 06:17
  • 1
    I don't understand what is your statement ? What do you mean by "host to host" ? the curl is indeed working from command line. The hosts are configured both in the Unix docker app and on Windows. I found out what you meant with host.docker.internal and it works so thanks – StarNab Aug 17 '21 at 08:15
  • What I tried to say is: you were not using curl from the docker container. Rather you were doing from your windows computer to your (same) windows computer – online Thomas Aug 17 '21 at 11:01
  • No I'm not. I am inside an Ubuntu distribution using WSL. It has it's own IP (etc). And the prompt "ubuntu@LAPTOP-QD358FF4:/var/my-site$" But it seems to not be the docker container itself. The way this functions is not absolutely clear to me to be honest at the moment. – StarNab Aug 17 '21 at 12:33
  • WSL = still not inside the docker container as you noticed – online Thomas Aug 17 '21 at 12:34

0 Answers0