@@ -37,6 +37,7 @@ class DockerActions implements IDeployActions {
3737
3838 private Client $ guzzleClient ;
3939 private bool $ useSocket = false ; # for `pullImage` function, to detect can be stream used or not.
40+ private string $ socketAddress ;
4041
4142 public function __construct (
4243 private readonly LoggerInterface $ logger ,
@@ -465,7 +466,8 @@ public function pullImage(
465466 $ this ->logger ->info (sprintf ('Image(%s) pulled successfully. ' , $ imageId ));
466467 }
467468 } catch (GuzzleException $ e ) {
468- $ r = sprintf ('Failed to pull image, GuzzleException occur: %s ' , $ e ->getMessage ());
469+ $ urlToLog = $ this ->useSocket ? $ this ->socketAddress : $ dockerUrl ;
470+ $ r = sprintf ('Failed to pull image via "%s", GuzzleException occur: %s ' , $ urlToLog , $ e ->getMessage ());
469471 }
470472 return $ r ;
471473 }
@@ -661,7 +663,8 @@ public function ping(string $dockerUrl): bool {
661663 return true ;
662664 }
663665 } catch (Exception $ e ) {
664- $ this ->logger ->error ('Could not connect to Docker daemon ' , ['exception ' => $ e ]);
666+ $ urlToLog = $ this ->useSocket ? $ this ->socketAddress : $ url ;
667+ $ this ->logger ->error ('Could not connect to Docker daemon via {url} ' , ['exception ' => $ e , 'url ' => $ urlToLog ]);
665668 error_log ($ e ->getMessage ());
666669 }
667670 return false ;
@@ -823,21 +826,20 @@ public function healthcheckContainer(string $containerId, DaemonConfig $daemonCo
823826 }
824827
825828 public function buildDockerUrl (DaemonConfig $ daemonConfig ): string {
826- if (file_exists ($ daemonConfig ->getHost ())) {
827- return 'http://localhost ' ;
828- }
829- return $ daemonConfig ->getProtocol () . ':// ' . $ daemonConfig ->getHost ();
829+ // When using local socket, we the curl URL needs to be set to http://localhost
830+ return $ this ->isLocalSocket ($ daemonConfig ->getHost ()) ? 'http://localhost ' : $ daemonConfig ->getProtocol () . ':// ' . $ daemonConfig ->getHost ();
830831 }
831832
832833 public function initGuzzleClient (DaemonConfig $ daemonConfig ): void {
833834 $ guzzleParams = [];
834- if (file_exists ($ daemonConfig ->getHost ())) {
835+ if ($ this -> isLocalSocket ($ daemonConfig ->getHost ())) {
835836 $ guzzleParams = [
836837 'curl ' => [
837838 CURLOPT_UNIX_SOCKET_PATH => $ daemonConfig ->getHost (),
838839 ],
839840 ];
840841 $ this ->useSocket = true ;
842+ $ this ->socketAddress = $ daemonConfig ->getHost ();
841843 } elseif ($ daemonConfig ->getProtocol () === 'https ' ) {
842844 $ guzzleParams = $ this ->setupCerts ($ guzzleParams );
843845 }
@@ -900,4 +902,16 @@ private function buildDefaultGPUDeviceRequests(): array {
900902 ],
901903 ];
902904 }
905+
906+ private function isLocalSocket (string $ host ): bool {
907+ $ isLocalPath = strpos ($ host , '/ ' ) === 0 ;
908+ if ($ isLocalPath ) {
909+ if (!file_exists ($ host )) {
910+ $ this ->logger ->error ('Local docker socket path {path} does not exist ' , ['path ' => $ host ]);
911+ } elseif (!is_writable ($ host )) {
912+ $ this ->logger ->error ('Local docker socket path {path} is not writable ' , ['path ' => $ host ]);
913+ }
914+ }
915+ return $ isLocalPath ;
916+ }
903917}
0 commit comments