I use Docker Windows Toolbox
I created the docker container with PHP-FPM:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock php:7.0-fpm-alpine
If I use curl directly from container shell:
curl --unix-socket /var/run/docker.sock http://containers/json
I got correct answer.
But if use PHP code:
$socket = stream_socket_client('unix:///var/run/docker.sock', $errno, $errstr);
if ($socket){
$request = 'GET /version HTTP/1.1'."\r\n";
$request.= 'Connection: Close'."\r\n\r\n";
fwrite($socket,$request);
$response = stream_get_contents($socket);
fclose($socket);
print_r($response);
}
else {
print_r($errstr);
}
then I got the error below:
Warning: stream_socket_client(): unable to connect to unix:///var/run/docker.sock (Permission denied)
PHP works under www-data user. I tried to run PHP-FPM under root but got PHP-FPM error that I can't run php under root.
I tried to create "docker" user/group inside the container then ran PHP-FPM under "docker" user/group but it not helped.
How can I fix it?