一条命令安装docker

前言

不搞那么复杂,就一行命令搞定:

1
bash <(curl -fSsL http://www.chenb.top/deploy/docker-install.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
#!/bin/bash
# install docker
# bash <(curl -fSsL http://www.chenb.top/deploy/docker-install.sh)

now=`date +%s`
function log() {
echo "[$((`date +%s` - now ))] ## $@ ##"
}

log "Installation start at `date`"

# check
[[ `whoami` != "root" ]] && echo "Root Privilege needed, use sudo please." && exit 1
OS=`awk -F= '/^NAME/{print $2}' /etc/os-release | sed "s/\"//g"`
if [[ "$OS" == "Ubuntu" ]];then
:
elif [[ "$OS" == "CentOS Linux" ]];then
OS="CentOS"
else
echo "Unknown OS: \"$OS\", exit"
exit 2
fi

# install docker
log "install and upgrade docker"
if [[ "$OS" == "Ubuntu" ]];then
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository -u "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y install docker-ce
fi

if [[ "$OS" == "CentOS" ]];then
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
systemctl enable docker && systemctl start docker
fi

# congifure mirror and insecure registries
log "congifure mirror and insecure registries"
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://m.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker
log "Installation end at `date`"

启动Jenkins的命令

1
2
3
4
5
6
7
8
9
10
docker run \
--name jenkins \
-d \
-u root \
-p 8080:8080 \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-e TZ=Asia/Shanghai \
-v "$HOME":/home \
jenkinsci/blueocean

参考链接

GitHub项目地址:https://github.com/chenbin-353549444/deploy
参考别人的项目:https://github.com/wrfly/k8s-install.sh
官网安装链接:https://docs.docker.com/install/linux/docker-ce/centos/

文章目录
  1. 1. 前言
    1. 1.1. 脚本代码
    2. 1.2. 启动Jenkins的命令
    3. 1.3. 参考链接