前言
注意:Debian10x64已通过自测,Ubuntu和CentOS暂未自测,此处仅做记录备用
安装前必读
Linux 内核:官方建议 3.10 以上
注意:本文的命令使用的是 root 用户登录执行,不是 root 的话所有命令前面要加 sudo
准备工作
- 查看当前的内核版本,命令:
uname -r
Docker 对Linux 内核版本的最低要求是3.10,如果内核版本低于3.10 会缺少一些运行Docker 容器的功能。
- 更新软件包
1 2 3 4 5
| apt update
yum update
|
- 卸载旧版本(如果之前安装过的话)
1 2 3 4 5 6 7
| apt remove docker docker-engine docker.io containerd runc
yum remove docker docker-client docker-client-latest \ docker-common docker-latest docker-latest-logrotate \ docker-logrotate docker-engine
|
安装Docker
- 添加使用 HTTPS 传输的软件包以及 CA 证书
1 2 3 4 5
| apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common lsb-release
yum install -y yum-utils device-mapper-persistent-data lvm2
|
- 设置源,添加软件源的 GPG 密钥
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
- 将 Docker 版本库添加到APT源
1 2 3 4 5 6 7 8 9 10 11
| add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
- 用新添加的 Docker 软件包来进行升级更新
1 2 3 4 5
| apt update
yum update
|
- 确保要从Docker repo而不是默认的Debian repo安装(CentOS无需此步骤)
1 2
| apt-cache policy docker-ce
|
- 安装 Docker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| apt install docker-ce
apt-cache madison docker-ce apt install docker-ce=<VERSION>
yum install docker-ce docker-ce-cli containerd.io
yum list docker-ce --showduplicates | sort -r yum install -y docker-ce-<VERSION> docker-ce-cli-<VERSION> containerd.io
|
- 启动Docker(Debian/Ubuntu无需此步骤)
- 检查 Docker 是否安装成功
- 修改镜像源以提升镜像拉取速度
国内服务器大概率无法pull镜像,通过VIM编辑文件,添加以下内容:
1 2 3 4
| { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://hub-mirror.c.163.com","https://registry.docker-cn.com"], "insecure-registries": ["10.0.0.12:5000"] }
|
修改镜像源命令如下:
1 2 3 4 5
| vim /etc/docker/daemon.json
systemctl restart docker
|