From a04c2ecb442c3ed8a4eac60a6bb9e3413111d13c Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Fri, 4 Sep 2026 16:38:24 +0200 Subject: [PATCH] fix(docker): preserve restart policies when stopping containers --- app/Actions/Application/StopApplication.php | 2 -- app/Actions/Application/StopApplicationPreview.php | 2 -- app/Actions/Database/StopDatabase.php | 2 -- app/Actions/Service/StopServiceApplication.php | 5 +---- .../ApplicationStoppedAfterRestartLimitTest.php | 2 +- tests/Unit/StopActionsPersistStatusTest.php | 11 +++++++++++ 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/Actions/Application/StopApplication.php b/app/Actions/Application/StopApplication.php index fcf1e1d0fe..12ac569009 100644 --- a/app/Actions/Application/StopApplication.php +++ b/app/Actions/Application/StopApplication.php @@ -44,8 +44,6 @@ class StopApplication $commands = [dockerStopCommand($timeout, $containerName, $server)]; if ($removeContainers) { $commands[] = "docker rm -f $containerName"; - } else { - array_unshift($commands, "docker update --restart=no $containerName"); } instant_remote_process(command: $commands, server: $server, throwError: false); diff --git a/app/Actions/Application/StopApplicationPreview.php b/app/Actions/Application/StopApplicationPreview.php index af5f3fc0f0..8bb3a3dc08 100644 --- a/app/Actions/Application/StopApplicationPreview.php +++ b/app/Actions/Application/StopApplicationPreview.php @@ -20,8 +20,6 @@ class StopApplicationPreview $commands = [dockerStopCommand($application->settings->stopGracePeriodSeconds(), $containerName, $server)]; if ($removeContainer) { $commands[] = "docker rm -f $containerName"; - } else { - array_unshift($commands, "docker update --restart=no $containerName"); } instant_remote_process($commands, $server, false); } diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.php index 8005311b5b..d3c6fafc4d 100644 --- a/app/Actions/Database/StopDatabase.php +++ b/app/Actions/Database/StopDatabase.php @@ -62,8 +62,6 @@ class StopDatabase $commands = [dockerStopCommand($timeout, $containerName, $server)]; if ($removeContainer) { $commands[] = "docker rm -f $containerName"; - } else { - array_unshift($commands, "docker update --restart=no $containerName"); } instant_remote_process(command: $commands, server: $server, throwError: false); } diff --git a/app/Actions/Service/StopServiceApplication.php b/app/Actions/Service/StopServiceApplication.php index 11ad337ed6..1b53472656 100644 --- a/app/Actions/Service/StopServiceApplication.php +++ b/app/Actions/Service/StopServiceApplication.php @@ -22,10 +22,7 @@ class StopServiceApplication if ($removeContainer) { $commands = ["docker rm -f {$containerName}"]; } else { - $commands = [ - "docker update --restart=no {$containerName}", - "docker stop {$containerName}", - ]; + $commands = ["docker stop {$containerName}"]; } instant_remote_process($commands, $server, throwError: ! $removeContainer); diff --git a/tests/Feature/ApplicationStoppedAfterRestartLimitTest.php b/tests/Feature/ApplicationStoppedAfterRestartLimitTest.php index 58ebb8c703..f5875adb2c 100644 --- a/tests/Feature/ApplicationStoppedAfterRestartLimitTest.php +++ b/tests/Feature/ApplicationStoppedAfterRestartLimitTest.php @@ -126,7 +126,7 @@ it('can stop an application without removing its containers', function () { expect($removeContainers)->not->toBeNull() ->and($removeContainers->getDefaultValue())->toBeTrue() - ->and($action)->toContain('docker update --restart=no') + ->and($action)->not->toContain('docker update --restart=no') ->and($action)->toContain('if ($removeContainers)'); }); diff --git a/tests/Unit/StopActionsPersistStatusTest.php b/tests/Unit/StopActionsPersistStatusTest.php index 67a7a8c6f9..a6d8d2fc1e 100644 --- a/tests/Unit/StopActionsPersistStatusTest.php +++ b/tests/Unit/StopActionsPersistStatusTest.php @@ -6,6 +6,17 @@ it('persists exited status when stopping standalone databases', function () { expect($action)->toContain("'status' => 'exited'"); }); +it('does not change Docker restart policies when retaining stopped containers', function (string $actionPath) { + $action = file_get_contents(__DIR__.'/../../'.$actionPath); + + expect($action)->not->toContain('docker update --restart=no'); +})->with([ + 'applications' => 'app/Actions/Application/StopApplication.php', + 'application previews' => 'app/Actions/Application/StopApplicationPreview.php', + 'service applications' => 'app/Actions/Service/StopServiceApplication.php', + 'standalone databases' => 'app/Actions/Database/StopDatabase.php', +]); + it('persists exited status for every full application stop path', function () { $action = file_get_contents(__DIR__.'/../../app/Actions/Application/StopApplication.php');