My Laravel application is working in docker with the default sail configuration.
I’m trying to access a route of my API in my API and i’m getting an error. It’s seems like Laravel can’t call itself.
The code :
@php
$defaultProductImageBase64 = base64_encode(file_get_contents("http://api.localhost/images/savors/default-product.png"));
@endphp
The error :
file_get_contents(http://api.localhost/images/savors/default-product.png): Failed to open stream: HTTP request failed!
I tried to use the container name instead of the “api.localhost” but I always get the same error. I also tried “host.docker.internal”.
Informations:
- The URL is working in my browser.
- The file_get_contents works with a URL of another website.
- A docker exec of curl in the container work with the url “http://CONTAINER_NAME” and “http://host.docker.internal