1. 更换Ubuntu的安装源
首先要更换ubuntu的源,否则安装过程网速会慢到抓狂,
1.1. 备份souces.list
$ cp /etc/apt/sources.list /etc/apt/sources.list.back
1.2. 替换/etc/apt/sources.list中的内容
这里使用的是阿里源
# deal Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
1.3. 更新apt包索引
$sudo apt-get update
2. 参照官方教程安装docker ce最新版本
2.1. 删除老的docker,如果有的话
$ sudo apt-get remove docker docker-engine docker.io
2.2. 设置仓库
- 安装HTTPs传输工具,运行apt来使用仓库
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
- 添加docker官方的GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
接下来通过搜索指纹的最后8个特征,来验证一下当前你的机器是否拥有这个指纹的密钥了
$ sudo apt-key fingerprint 0EBFCD88
控制台输出如下结果
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
- 运行如下命来来建立稳定的仓库
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
2.3. 安装DOCKER CE
- 先更新一下apt包的索引
$ sudo apt-get update
- 安装
$ sudo apt-get install docker-ce
- 如何安装指定版本的docker ce
有的时候你可能需要安装指定版本的docker ce,这个时候你可以通过命令先查看一下你当前的仓库上有哪些版本
$ apt-cache madison docker-ce
这个时候你可以得到如下的输出,
docker-ce | 17.12.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xeni al/stable amd64 Packages
...
然后你就可以安装你所需的了
$ sudo apt-get install docker-ce=<VERSION>
3. 修改docker的镜像源
申请一个阿里云的账号,然后打开如下链接
https://cr.console.aliyun.com/#/accelerator
打开容器镜像服务 -> 镜像加速器,参照里面的操作文档设置。