-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-docker.sh
executable file
·68 lines (56 loc) · 1.28 KB
/
install-docker.sh
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
#!/bin/bash
# exit when any command fails
set -e
echo
echo "INSTALLING DOCKER"
echo
if [[ \
$(dpkg-query -W -f='${Status}' docker-ce 2>/dev/null | grep -c "ok installed") -eq 1 && \
$(dpkg-query -W -f='${Status}' docker-ce-cli 2>/dev/null | grep -c "ok installed") -eq 1 && \
$(dpkg-query -W -f='${Status}' containerd.io 2>/dev/null | grep -c "ok installed") -eq 1 \
]]
then
echo "Docker already installed"
exit 0
fi
echo "Install prerequisites"
echo
sudo apt -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
echo
echo "Add Docker key"
echo
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo
echo "Add docker repo. THIS MAY FAIL IF YOU'RE NOT USING UBUNTU!"
echo
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
echo
echo "Install docker packages"
echo
sudo apt -y install docker-ce docker-ce-cli containerd.io
echo
echo "Test docker as root"
echo
sudo docker run hello-world
echo
echo "Add ${USER} to docker group"
echo
sudo usermod -aG docker $USER
echo
echo "Test docker as regular user"
echo
newgrp docker << END
docker run hello-world
END
echo
echo "DOCKER SUCCESFULLY INSTALLED"
echo
exit 0