-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.ps1
49 lines (49 loc) · 1.69 KB
/
docker.ps1
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
# sudo pwsh -Command "iex '& ([scriptblock]::Create((iwr https://raw.githubusercontent.com/abdullahfarook/kube/main/docker.ps1)))'"
param(
[bool]$uninstall = $false
)
function Write-Log {
param (
[string]$message,
[string]$level = "INF"
)
$timestamp = Get-Date -Format "HH:mm:ss"
if ($level -eq "ERR") {
Write-Host -NoNewline "[$timestamp "
Write-Host -NoNewline "$level] " -ForegroundColor Red
write-host $message
}else{
Write-Host -NoNewline "[$timestamp "
Write-Host -NoNewline "$level] " -ForegroundColor Green
write-host $message
}
}
function Write-Err {
param (
[string]$message
)
Write-Log $message "ERR"
exit 1
}
if ($uninstall -eq $true) {
Write-Log "Uninstalling docker..."
apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli docker-compose-plugin
apt-get autoremove -y --purge docker-engine docker docker.io docker-ce docker-compose-plugin
rm -rf /var/lib/docker /etc/docker
rm /etc/apparmor.d/docker
groupdel docker
rm -rf /var/run/docker.sock
rm -rf /var/lib/containerd
rm -r ~/.docker
Write-Log "Docker uninstalled successfully"
exit 0
}
apt update
apt --yes --no-install-recommends install apt-transport-https ca-certificates curl software-properties-common
wget --quiet --output-document=- https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository --yes "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release --codename --short) stable"
apt update
apt --yes install docker-ce
usermod -aG docker $USER
systemctl enable docker
Write-Log "Docker installed successfully"