Last active
May 13, 2025 09:46
-
-
Save olljanat/340b4033eb24d8d33ec75f2c3c3b6b3d to your computer and use it in GitHub Desktop.
Revisions
-
olljanat revised this gist
Dec 7, 2018 . 1 changed file with 15 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,13 @@ param ( [switch]$RenameOrphanLayers ) If ($RenameOrphanLayers) { Write-Warning "$($env:COMPUTERNAME) -RenameOrphanLayers option enabled, will rename all orphan layers" } # Get known layers on Docker images [array]$ImageDetails += docker images -q | ForEach { docker inspect $_ | ConvertFrom-Json } ForEach ($Image in $ImageDetails) { $ImageLayer = $Image.GraphDriver.Data.dir @@ -12,8 +19,7 @@ ForEach ($Image in $ImageDetails) { } # Get known layes on Docker containers [array]$ContainerDetails = docker ps -a -q | ForEach { docker inspect $_ | ConvertFrom-Json} ForEach ($Container in $ContainerDetails) { [array]$ContainerLayers += $Container.GraphDriver.Data.dir } @@ -33,6 +39,11 @@ ForEach ($Layer in $LayersOnDisk) { $LayerSize = (Get-ChildItem -Path $Layer -Recurse -ErrorAction:SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum $OrphanLayersTotal += $LayerSize Write-Warning "$($env:COMPUTERNAME) - Found orphan layer: $($Layer -Replace '\r\n','') with size: $(($LayerSize -Replace '\r\n','') / 1MB) MB" If (($RenameOrphanLayers) -and ($Layer -notlike "*-removing")) { $LayerNewPath = $Layer + "-removing" Rename-Item -Path $Layer -NewName $LayerNewPath } } } -
olljanat revised this gist
Dec 7, 2018 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Get known layers on Docker images $ImageInspect = docker images -q | ForEach { docker inspect $_ } $ImageDetails = $ImageInspect | ConvertFrom-Json ForEach ($Image in $ImageDetails) { $ImageLayer = $Image.GraphDriver.Data.dir @@ -12,7 +12,7 @@ ForEach ($Image in $ImageDetails) { } # Get known layes on Docker containers $ContainerInspect = docker ps -a -q | ForEach { docker inspect $_ } $ContainerDetails = $ContainerInspect | ConvertFrom-Json ForEach ($Container in $ContainerDetails) { [array]$ContainerLayers += $Container.GraphDriver.Data.dir @@ -32,12 +32,12 @@ ForEach ($Layer in $LayersOnDisk) { [array]$OrphanLayer += $Layer $LayerSize = (Get-ChildItem -Path $Layer -Recurse -ErrorAction:SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum $OrphanLayersTotal += $LayerSize Write-Warning "$($env:COMPUTERNAME) - Found orphan layer: $($Layer -Replace '\r\n','') with size: $(($LayerSize -Replace '\r\n','') / 1MB) MB" } } Write-Host "$($env:COMPUTERNAME) - Layers on disk: $($LayersOnDisk.count)" Write-Host "$($env:COMPUTERNAME) - Image layers: $($UniqueImageLayers.count)" Write-Host "$($env:COMPUTERNAME) - Container layers: $($ContainerLayers.count)" $OrphanLayersTotalMB = $OrphanLayersTotal / 1MB Write-Warning "$($env:COMPUTERNAME) - Found $($OrphanLayer.count) orphan layers with total size $OrphanLayersTotalMB MB" -
olljanat created this gist
Dec 5, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ # Get known layers on Docker images $ImageInspect = docker inspect $(docker images -q) $ImageDetails = $ImageInspect | ConvertFrom-Json ForEach ($Image in $ImageDetails) { $ImageLayer = $Image.GraphDriver.Data.dir [array]$ImageLayers += $ImageLayer $LayerChain = Get-Content "$ImageLayer\layerchain.json" If ($LayerChainFileContent -ne "null") { [array]$ImageParentLayers += $LayerChain | ConvertFrom-Json } } # Get known layes on Docker containers $ContainerInspect = docker inspect $(docker ps -a -q) $ContainerDetails = $ContainerInspect | ConvertFrom-Json ForEach ($Container in $ContainerDetails) { [array]$ContainerLayers += $Container.GraphDriver.Data.dir } # Get layers on disk $LayersOnDisk = (Get-ChildItem -Path C:\ProgramData\Docker\windowsfilter -Directory).FullName $ImageLayers += $ImageParentLayers $UniqueImageLayers = $ImageLayers | Select-Object -Unique [array]$KnownLayers = $UniqueImageLayers $KnownLayers += $ContainerLayers # Find orphan layers $OrphanLayersTotal = 0 ForEach ($Layer in $LayersOnDisk) { If ($KnownLayers -notcontains $Layer) { [array]$OrphanLayer += $Layer $LayerSize = (Get-ChildItem -Path $Layer -Recurse -ErrorAction:SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum $OrphanLayersTotal += $LayerSize Write-Warning "Found orphan layer: $($Layer -Replace '\r\n','') with size: $(($LayerSize -Replace '\r\n','') / 1MB) MB" } } Write-Host "Layers on disk: $($LayersOnDisk.count)" Write-Host "Image layers: $($UniqueImageLayers.count)" Write-Host "Container layers: $($ContainerLayers.count)" $OrphanLayersTotalMB = $OrphanLayersTotal / 1MB Write-Warning "Found $($OrphanLayer.count) orphan layers with total size $OrphanLayersTotalMB MB"