From 61c294c52911b6ca387c189190564eccb48cd5a2 Mon Sep 17 00:00:00 2001 From: Eric Keller Date: Fri, 23 Feb 2024 11:16:15 +0100 Subject: [PATCH] Consider if the installed version is not matching the parametrized version --- .../Install-DockerCE/install-docker-ce.ps1 | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/helpful_tools/Install-DockerCE/install-docker-ce.ps1 b/helpful_tools/Install-DockerCE/install-docker-ce.ps1 index ae2d712..e2ff2b4 100644 --- a/helpful_tools/Install-DockerCE/install-docker-ce.ps1 +++ b/helpful_tools/Install-DockerCE/install-docker-ce.ps1 @@ -376,12 +376,23 @@ Install-ContainerHost # # Install, register, and start Docker # - if (Test-Docker) + if (Test-Docker-Version) { - Write-Output "Docker is already installed." + Write-Output "Docker is already installed with specific version." } else { + if (Test-Docker) + { + #Stop all containers + docker stop $(docker ps -aq) + + #Halt the docker service + Stop-Service -Name docker + + #Unregister the docker service + dockerd --unregister-service + } if ($NATSubnet) { Install-Docker -DockerPath $DockerPath -DockerDPath $DockerDPath -NATSubnet $NATSubnet -ContainerBaseImage $ContainerBaseImage @@ -710,6 +721,16 @@ Test-Docker() } +function +Test-Docker-Version() +{ + $version = & docker version --format "{{.Server.Version}}" + Write-Host "Installed version:" $version + Write-Host "Target version:" $DockerVersion + return ($version -eq $DockerVersion) +} + + function Wait-Docker() { @@ -754,3 +775,4 @@ catch { Write-Error $_ } +