@@ -131,43 +131,85 @@ public async Task BuildImageAsync(string contextPath, string dockerfilePath, str
131131        } 
132132    } 
133133
134-     public  Task < bool >  CheckIfRunningAsync ( CancellationToken  cancellationToken ) 
134+     public  async   Task < bool >  CheckIfRunningAsync ( CancellationToken  cancellationToken ) 
135135    { 
136-         var  spec  =  new  ProcessSpec ( "docker" ) 
136+         // First check if Docker daemon is running using the same check that DCP uses 
137+         if  ( ! await  CheckDockerDaemonAsync ( cancellationToken ) . ConfigureAwait ( false ) ) 
137138        { 
138-             Arguments  =  "buildx version" , 
139+             return  false ; 
140+         } 
141+ 
142+         // Then check if Docker buildx is available 
143+         return  await  CheckDockerBuildxAsync ( cancellationToken ) . ConfigureAwait ( false ) ; 
144+     } 
145+ 
146+     private  async  Task < bool >  CheckDockerDaemonAsync ( CancellationToken  cancellationToken ) 
147+     { 
148+         var  dockerRunningSpec  =  new  ProcessSpec ( "docker" ) 
149+         { 
150+             Arguments  =  "container ls -n 1" , 
139151            OnOutputData  =  output => 
140152            { 
141-                 logger . LogInformation ( "docker buildx version  (stdout): {Output}" ,  output ) ; 
153+                 logger . LogInformation ( "docker container ls  (stdout): {Output}" ,  output ) ; 
142154            } , 
143155            OnErrorData  =  error => 
144156            { 
145-                 logger . LogInformation ( "docker buildx version  (stderr): {Error}" ,  error ) ; 
157+                 logger . LogInformation ( "docker container ls  (stderr): {Error}" ,  error ) ; 
146158            } , 
147159            ThrowOnNonZeroReturnCode  =  false , 
148160            InheritEnv  =  true 
149161        } ; 
150162
151-         logger . LogInformation ( "Running Docker CLI with arguments: {ArgumentList}" ,  spec . Arguments ) ; 
152-         var  ( pendingProcessResult ,  processDisposable )  =  ProcessUtil . Run ( spec ) ; 
163+         logger . LogInformation ( "Checking if Docker daemon is running with arguments: {ArgumentList}" ,  dockerRunningSpec . Arguments ) ; 
164+         var  ( pendingDockerResult ,  dockerDisposable )  =  ProcessUtil . Run ( dockerRunningSpec ) ; 
165+ 
166+         await  using  ( dockerDisposable ) 
167+         { 
168+             var  dockerResult  =  await  pendingDockerResult . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ; 
153169
154-         return  CheckDockerBuildxAsync ( pendingProcessResult ,  processDisposable ,  cancellationToken ) ; 
170+             if  ( dockerResult . ExitCode  !=  0 ) 
171+             { 
172+                 logger . LogError ( "Docker daemon is not running. Exit code: {ExitCode}." ,  dockerResult . ExitCode ) ; 
173+                 return  false ; 
174+             } 
155175
156-         async  Task < bool >  CheckDockerBuildxAsync ( Task < ProcessResult >  pendingResult ,  IAsyncDisposable  processDisposable ,  CancellationToken  ct ) 
176+             logger . LogInformation ( "Docker daemon is running." ) ; 
177+             return  true ; 
178+         } 
179+     } 
180+ 
181+     private  async  Task < bool >  CheckDockerBuildxAsync ( CancellationToken  cancellationToken ) 
182+     { 
183+         var  buildxSpec  =  new  ProcessSpec ( "docker" ) 
157184        { 
158-             await  using  ( processDisposable ) 
185+             Arguments  =  "buildx version" , 
186+             OnOutputData  =  output => 
187+             { 
188+                 logger . LogInformation ( "docker buildx version (stdout): {Output}" ,  output ) ; 
189+             } , 
190+             OnErrorData  =  error => 
159191            { 
160-                 var  processResult  =  await  pendingResult . WaitAsync ( ct ) . ConfigureAwait ( false ) ; 
192+                 logger . LogInformation ( "docker buildx version (stderr): {Error}" ,  error ) ; 
193+             } , 
194+             ThrowOnNonZeroReturnCode  =  false , 
195+             InheritEnv  =  true 
196+         } ; 
161197
162-                 if  ( processResult . ExitCode  !=  0 ) 
163-                 { 
164-                     logger . LogError ( "Docker buildx version failed with exit code {ExitCode}." ,  processResult . ExitCode ) ; 
165-                     return  false ; 
166-                 } 
198+         logger . LogInformation ( "Checking Docker buildx with arguments: {ArgumentList}" ,  buildxSpec . Arguments ) ; 
199+         var  ( pendingBuildxResult ,  buildxDisposable )  =  ProcessUtil . Run ( buildxSpec ) ; 
167200
168-                 logger . LogInformation ( "Docker buildx is available and running." ) ; 
169-                 return  true ; 
201+         await  using  ( buildxDisposable ) 
202+         { 
203+             var  buildxResult  =  await  pendingBuildxResult . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ; 
204+ 
205+             if  ( buildxResult . ExitCode  !=  0 ) 
206+             { 
207+                 logger . LogError ( "Docker buildx version failed with exit code {ExitCode}." ,  buildxResult . ExitCode ) ; 
208+                 return  false ; 
170209            } 
210+ 
211+             logger . LogInformation ( "Docker buildx is available and running." ) ; 
212+             return  true ; 
171213        } 
172214    } 
173215
0 commit comments