-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClear-DockerStorage.ps1
More file actions
69 lines (52 loc) · 1.67 KB
/
Clear-DockerStorage.ps1
File metadata and controls
69 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Clear docker related storage.
.DESCRIPTION
Removes all docker images and volumes. Runs docker-leak-check to clear
additional storage
#>
$ErrorActionPreference = 'Stop';
Write-Host 'The Clear-DockerStorage script should only be run after a reboot';
$selection = Read-Host -Prompt 'Reboot computer? [y/n]';
if ($selection -eq 'y') {
Write-Host 'Rerun the script after reboot is complete';
Restart-Computer -Force;
return;
}
# Stop current container
$dockerArgs = @('rm','--force','buildbot');
Write-Host ('docker {0}' -f ($dockerArgs -join " "));
$p = Start-Process 'docker.exe' -ArgumentList $dockerArgs -PassThru -NoNewWindow -Wait;
if ($p.ExitCode -ne 0) {
Write-Warning 'An error occurred when stopping buildbot container';
}
# Run system prune
$dockerArgs = @(
'system',
'prune',
'--all',
'--volumes',
'--force'
)
Write-Host ('docker {0}' -f ($dockerArgs -join " "));
$p = Start-Process 'docker.exe' -ArgumentList $dockerArgs -PassThru -NoNewWindow -Wait;
if ($p.ExitCode -ne 0) {
Write-Error 'Unable to prune system';
}
# Run docker leak check
$leakCheckExe = Join-Path $PSScriptRoot 'docker-leak-check.exe';
if (!(Test-Path $leakCheckExe)) {
$scriptArgs = @{
Uri = 'https://github.com/lowenna/docker-leak-check/raw/refs/heads/master/docker-leak-check.exe';
OutFile = $leakCheckExe;
};
if (Test-Path env:HTTPS_PROXY) {
$scriptArgs['Proxy'] = $env:HTTPS_PROXY;
}
Invoke-WebRequest @scriptArgs;
}
Stop-Service docker;
$dockerArgs = @('-remove')
Write-Host ('docker-leak-check {0}' -f ($dockerArgs -join " "));
$p = Start-Process $leakCheckExe -ArgumentList $dockerArgs -PassThru -NoNewWindow -Wait;
Start-Service docker;