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
|
#!/bin/bash
sudo yum remove docker docker-client docker-client-latest \
docker-common docker-latest docker-latest-logrotate \
docker-logrotate docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.ustc.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum makecache fast
# 安装最新版并创建docker组(里面没有用户)
sudo yum install -y docker-ce docker-ce-cli containerd.io
# 安装指定版本
# 列出仓库可用的所有版本
# yum list docker-ce --showduplicates | sort -r
# 对于3:20.10.6-3.el8,它的版本号是:到-中间的部分,也就是: 20.10.6
# 将<VERSION_STRING>替换为20.10.6即可
# sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
# 将用户添加到docker组
sudo usermod -aG docker ${USER}
# 开机启动
sudo systemctl enable docker
# start docker
sudo systemctl start docker
sudo chmod a+rw /var/run/docker.sock
# update registry mirrors
sudo touch /etc/docker/daemon.json
sudo cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://dockerproxy.com",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://cr.console.aliyun.com"
]
}
EOF
sudo systemctl restart docker
# hello-world
docker run hello-world
|