[教程]在国内VPS上捣鼓Docker-CE
前情提要

Docker
昨日折腾了半个小时,才通过镜像源安装上Docker-CE(社区版)。主要是有项目要在Docker跑,但是海外Docker Hub的速度太慢,镜像源不断地切来切去(那9kb/s的速度会让你窒息)。首先要安装Docker,这里选择CentOS7,对应要求是64位系统、内核版本3.10以上。
删除旧版本Docker
1
2
3
4
5
6
7
8
9
10
|
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
|
换yum源(可选)
国内的话,这边使用的是阿里云的开源镜像站,你可以使用163、华为云等开源镜像站,但是博主观察了下,也就阿里云和清华大学的TUNA较为完整。
1
2
3
|
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
|
安装必要组件&环境配置
为了避免软件包缺失,这边建议先执行一遍
安装必要的组件
1
2
3
|
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
|
配置国内Docker源:
1
2
3
4
5
6
7
8
9
|
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"],
"registry-mirrors": ["https://registry.docker-cn.com"],
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF
|
添加阿里云Docker稳定版仓库:
1
|
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
|
安装最新版Docker
1
|
sudo yum install docker-ce docker-ce-cli containerd.io
|
安装特定Docker-CE版本
列出Docker-CE列表:
1
|
yum list docker-ce --showduplicates | sort -r
|
执行后,你会看到:
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
|
* updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirrors.aliyun.com
* epel: my.mirrors.thegigabit.com
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.aliyun.com
Available Packages
|
安装Docker-CE
1
|
sudo yum install docker-ce-18.03.1.ce
|
取决于你选择的版本,在这里我选择18.03.1
结语
这样,就可以在国内VPS上顺利启用Docker了,虽然第一次捣鼓了半天,但是蛮有收获!
1
2
3
4
5
6
|
#启动Docker
systemctl start docker.service
#停止Docker
systemctl stop docker.service
#卸载Docker (谨慎操作)
sudo rm -rf /var/lib/docker #默认安装目录
|
如果报错,可以使用下面指令恢复:
1
2
3
4
5
6
7
|
#删除异常源
sudo rm -f /etc/yum.repos.d/docker-ce.repo
#使用官方源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#所有配置修改都需要重启docker服务才能生效
systemctl daemon-reload
systemctl restart docker
|