-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-docker.sh.bak
101 lines (81 loc) · 3.23 KB
/
install-docker.sh.bak
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
#description: install docker, create user
USERNAME="qujsh" #you want to create who
PASSWORD=`head -c 32 /dev/urandom | base64 | cut -c 1-20 | tee ~/pass` #get the md5 value as random password
if [ $USER != "root" ]; then
echo "please use root account"
exit
fi
#INSTALL DOCKER USE PACKAGE
NAMES="docker_ce_cli containerd_io docker_ce docker_compose" #order is important, they are interdependence
DOCKER_CE='https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.5-3.el7.x86_64.rpm' #if it's too slow, you can set your own file store server
DOCKER_CE_CLI='https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.5-3.el7.x86_64.rpm'
CONTAINERD_IO='https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.5-3.1.el7.x86_64.rpm'
DOCKER_COMPOSE='https://github.com/docker/compose/releases/download/1.24.0/docker-compose-Linux-x86_64' #centos 64bit system docker-compose
DOWNLOAD='/root/download' #download place
DOCKER_PATH='/usr/bin/docker'
DOCKER_COMPOSE_PATH='/usr/local/bin/docker-compose'
REGISTRY_MIRROR='https://docker.mirrors.ustc.edu.cn' #you need replace your own Mirror accelerator
if [ ! -d $DOWNLOAD ]; then
mkdir $DOWNLOAD
fi
for name in $NAMES
do
if [ ! -f $DOWNLOAD/$name.rpm ]; then
NAME=$(echo $name | tr 'a-z' 'A-Z')
eval tmp=$(echo \$$NAME)
cd $DOWNLOAD && wget -O $name.rpm $tmp
if [ $? != 0 ]; then
echo "download $name package failed"
break
fi
fi
done
# remove first, and do add
yum list installed | grep docker | awk '{print $1}' | xargs yum remove -y
yum list installed | grep containerd | awk '{print $1}' | xargs yum remove -y
# set yum aliyun repos
if [ ! -f /etc/yum.repos.d/CentOS-Base.repo.backup ];then
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
if [ $? != 0 ]; then
echo 'yum repo set faild'
exit
fi
fi
#if [ ! -f $DOCKER_PATH ]; then
for name in $NAMES
do
if [ $name == "docker_compose" ]; then
cp $DOWNLOAD/$name.rpm $DOCKER_COMPOSE_PATH
chmod +x $DOCKER_COMPOSE_PATH
break
fi
yum install -y $DOWNLOAD/$name.rpm
done
if [ $? != 0 ]; then
echo 'docker install failed'
exit
fi
systemctl enable docker
#fi
mkdir -p /etc/docker && \
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["REGISTRY_MIRROR"]
}
EOF
sed -i "s#REGISTRY_MIRROR#$REGISTRY_MIRROR#" /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
#create user
useradd $USERNAME && \
echo $PASSWORD | passwd --stdin $USERNAME && \
gpasswd -a ${USERNAME} wheel
if [ $? != 0 ]; then
echo 'add user failed'
fi
gpasswd -a ${USERNAME} docker && \
systemctl restart docker && \
newgrp - docker