Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

blake.thompson's avatar

spatie/laravel-ray doesn't work with laravel sail from docker container

I've been fighting for a while now trying to get spatie/laravel-ray to work with a regular laravel sail app. After lots of debugging, I finally found that when ray was trying to talk to my host machine from the container, it was getting an error, "Could not resolve host: host.docker.internal".

laravel-ray's documents say that you must add extra_hosts to the docker-compose.yaml: #docker-compose.yml

services: site: image: nginx:stable-alpine container_name: nginx ports: - "80:80" depends_on: - php - db networks: - packt-api extra_hosts: # <-- this is required - "host.docker.internal:host-gateway" # <-- this is required

I've done that on the sail-8.0/app image, and it isn't working. Is this supposed to go somewhere else or something? Has any one made laravel-ray work with a sail application running on a docker container?

0 likes
7 replies
blake.thompson's avatar

Yes, I set the remote_path to RAY_REMOTE_PATH='/var/www/html/' (but have also tried /var/www/html), as well as the local_path to my project's root directory as RAY_LOCAL_PATH='/Users/{my-username}/test-projects/project/'

blake.thompson's avatar

There may be a difference in configuration, I'd like to see if there are any people in the Laracasts community that have successfully used spatie/laravel-ray in their sail applications that might be able to give some insight into how their configuration is set differently from mine.

blake.thompson's avatar

I never got this to work, but I could hack it into working by editing the ray.php config file, and manually entering my host IP address.

1 like
jesuuusete's avatar

I'm also having this issue, I had to solve it removing the env()'s variables from ray.php, and replacing them for the actual value that I gave them in the .env file. After that it worked as a charm. Hope this could help someone else

Daniel-Pablo's avatar

Hi I run into the same issue the way it works for me was following this guide of installation for SAIL

In the installation process, you got to specify that this will work with docker so you pull up the --docker flag

php artisan ray:publish-config --docker

https://spatie.be/docs/ray/v1/installation-in-your-project/laravel

this is an extra info just if you want to see it https://spatie.be/docs/ray/v1/environment-specific-configuration/docker

FOR Testing add this to PHPUnit.xml file, add the following:

<server name="RAY_HOST" value="host.docker.internal"/>

Just in case some one runs into the same

1 like
TheAnswerIsAlwaysMaybe's avatar

For anyone running into this issue: In my case unit-tests DID output normal ray() statements, but failed to show Exceptions that were thrown during unit tests.

I solved this by extending the runTest() method from tests/TestCase like so:

/**
* We want ray to output all throwable exceptions
* But by default it doesn't seem to do that, we need to override this method
* @throws Throwable
*/
protected function runTest()
{
    try {
        return parent::runTest();
    } catch (Throwable $exception) {
        ray($exception);
        throw $exception;
    }
}    		

Please or to participate in this conversation.