mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-21 08:25:45 +00:00
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:
@@ -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)."'";
|
||||
|
||||
Reference in New Issue
Block a user