Merge pull request #38419 from thaJeztah/fix_nuke_everything

PowerShell: fix "Nuke-Everything" failing to remove images
This commit is contained in:
Sebastiaan van Stijn 2018-12-31 21:24:01 +01:00 committed by GitHub
commit e0e9942dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 10 deletions

View File

@ -136,18 +136,14 @@ Function Nuke-Everything {
if ($(docker ps -aq | Measure-Object -line).Lines -gt 0) {
docker rm -f $(docker ps -aq)
}
$imageCount=($(docker images --format "{{.Repository}}:{{.ID}}" | `
select-string -NotMatch "windowsservercore" | `
select-string -NotMatch "nanoserver" | `
select-string -NotMatch "docker" | `
Measure-Object -line).Lines)
$allImages = $(docker images --format "{{.Repository}}#{{.ID}}")
$toRemove = ($allImages | Select-String -NotMatch "windowsservercore","nanoserver","docker")
$imageCount = ($toRemove | Measure-Object -line).Lines
if ($imageCount -gt 0) {
Write-Host -Foregroundcolor green "INFO: Non-base image count on control daemon to delete is $imageCount"
docker rmi -f `
$(docker images --format "{{.Repository}}:{{.ID}}" | `
select-string -NotMatch "windowsservercore" | `
select-string -NotMatch "nanoserver" | `
select-string -NotMatch "docker").ToString().Split(":")[1]
docker rmi -f ($toRemove | Foreach-Object { $_.ToString().Split("#")[1] })
}
} else {
Write-Host -ForegroundColor Magenta "WARN: Skipping cleanup of images and containers"