From 4553b91fa4edaa193c658887c1baffd63ca54b7e Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 24 Nov 2026 15:27:01 +0530 Subject: [PATCH] fix(docker): document container_status() and quote its argument container_status() returns false for any `docker inspect` failure, not only for a missing container: a daemon that is down or restarting, a socket error or a timeout look the same. Document that contract, and that 'running' includes paused and restarting containers while 'exited' covers created, exited and dead ones, so callers don't read false as "doesn't exist". The name is now passed through escapeshellarg(). Every caller passes one fixed name or an id from `docker-compose ps -q`, so the results don't change. --- php/class-ee-docker.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/php/class-ee-docker.php b/php/class-ee-docker.php index 76c526b3e..635fe415b 100644 --- a/php/class-ee-docker.php +++ b/php/class-ee-docker.php @@ -83,6 +83,15 @@ public static function boot_container( $container, $command = '' ) { } } + /** + * State of a container as `docker inspect` reports `.State.Running`. + * + * false doesn't mean the container doesn't exist: any inspect failure (no such container, daemon down or restarting, socket error) returns it. Callers that act on its absence (create, remove, "gone") must check that separately. + * + * @param string $container Container name or id. + * + * @return string|false 'running' while it runs, also when paused or restarting; 'exited' for any other state (created, exited, dead); false when inspect fails for any reason. Exits via EE::error() when docker isn't on PATH. + */ public static function container_status( $container ) { $exec_command = 'which docker'; @@ -92,7 +101,7 @@ public static function container_status( $container ) { if ( $ret ) { EE::error( 'Docker is not installed. Please install Docker to run EasyEngine.' ); } - $status = EE::launch( "docker inspect -f '{{.State.Running}}' $container" ); + $status = EE::launch( "docker inspect -f '{{.State.Running}}' " . escapeshellarg( $container ) ); if ( ! $status->return_code ) { if ( preg_match( '/true/', $status->stdout ) ) { return 'running';