fix(docker): replace deprecated stop flags with version-aware ones

Store each server's Docker version and build stop commands via
dockerStopCommand() so newer Docker uses --timeout instead of
deprecated --time/-t. Also show Docker version in server details.
This commit is contained in:
Andras Bacsai
2026-08-13 11:17:44 +02:00
parent 6481ffffcf
commit e79230cf37
32 changed files with 697 additions and 64 deletions
+55
View File
@@ -198,6 +198,61 @@ function checkMinimumDockerEngineVersion($dockerVersion)
return $dockerVersion;
}
function parseDockerEngineVersion(?string $rawVersion): ?string
{
if ($rawVersion === null || trim($rawVersion) === '') {
return null;
}
if (preg_match('/\d+\.\d+(?:\.\d+)?/', $rawVersion, $matches) !== 1) {
return null;
}
$parts = explode('.', $matches[0]);
return sprintf('%d.%d.%d', (int) $parts[0], (int) ($parts[1] ?? 0), (int) ($parts[2] ?? 0));
}
function dockerEngineVersionFromJson(?string $raw): ?string
{
if ($raw === null || trim($raw) === '') {
return null;
}
$decoded = json_decode($raw, true);
if (! is_array($decoded)) {
return null;
}
$version = $decoded['Server']['Version'] ?? null;
return is_string($version) ? parseDockerEngineVersion($version) : null;
}
function dockerStopTimeoutOption(?string $dockerVersion): string
{
$normalized = parseDockerEngineVersion($dockerVersion);
if ($normalized !== null && version_compare($normalized, '28.0.0', '>=')) {
return '--timeout';
}
return '--time';
}
function dockerStopCommand(int $timeout, string $containers, Server|string|null $dockerVersion = null): string
{
$version = $dockerVersion instanceof Server
? $dockerVersion->dockerVersion()
: $dockerVersion;
$option = dockerStopTimeoutOption($version);
$flag = $option === '--timeout'
? "--timeout={$timeout}"
: "--time={$timeout}";
return "docker stop {$flag} {$containers}";
}
function escapeShellValue(string $value): string
{
return "'".str_replace("'", "'\\''", $value)."'";