title: Unable to connect to unix:///var/run/docker.sock (Permission denied) from PHP code
body: <p>I use Docker Windows Toolbox</p>
  
  <p>I created the docker container with PHP-FPM:</p>
  
  <pre><code>docker run -d -v /var/run/docker.sock:/var/run/docker.sock php:7.0-fpm-alpine
  </code></pre>
  
  <p>If I use curl directly from container shell:</p>
  
  <pre><code>curl --unix-socket /var/run/docker.sock http://containers/json
  </code></pre>
  
  <p>I got correct answer.</p>
  
  <p>But if use PHP code:</p>
  
  <pre><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);
  }
  </code></pre>
  
  <p>then I got the error below:</p>
  
  <p><strong>Warning: stream_socket_client(): unable to connect to unix:///var/run/docker.sock (Permission denied)</strong></p>
  
  <p>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.</p>
  
  <p>I tried to create "docker" user/group inside the container then ran PHP-FPM under "docker" user/group but it not helped.</p>
  
  <p>How can I fix it?</p>