'PHP fails to access the docker socket via curl

My Code fails to reach the Docker Socket

    $client = new GuzzleHttp\Client();
    $test = $client->request('GET','http://v1.40/containers/json',[
        'curl' => [CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock']
    ]);

I only get a generic cURL error 7 from that and I´ve checked that the socket is available and working inside the Container with the cURL command from the cmd. Its only when i try to connect via PHP it fails ominously and frankly im out of ideas.



Solution 1:[1]

So just in case someone stumbles upon this in the future and has the same or a similar problem.

Guzzle was not the problem in this case but phpfpm. I did not realize that the phpfpm workers in the official php docker image used the www-data user by default. The way I used is to change the user in the www.conf (default /usr/local/etc/php-fpm.d/www.conf in docker)

user = root
group = root

you will have to append the -R flag to the run command to allow running the workers as root.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Philipp Susen