docker引擎支持Linux、Cloud、Windows和macOS,由于个人精力有限,我不可能一一实验,我选择在Ubuntu14.04上安装,本系列文章是通过学习官方文档整理而来。
安装要求
- Yakkety 16.10
 - Xenial 16.04 (LTS)
 - Trusty 14.04 (LTS)✔️
 
我的实验环境是Ubuntu 14.04 LTS, lsb_release -a可以查看版本号
1  | root@iZ23ldh8kudZ:~# lsb_release -a  | 
推荐安装额外包
linux-image-extra-*包,它允许Docker使用存储驱动,一般使用Docker都要安装,除非你有不得不说的理由。
1  | root@iZ23ldh8kudZ:~# sudo apt-get update  | 
使用镜像库安装Docker
安装Docker的方法有很多,选择一个你需要的即可,我是使用镜像库安装的。
- 配置镜像库安装Docker(大部分用户的选择)✔️
 - 下载DEB包安装Docker
 
第一次在新机器上安装Docker的时候,需要配置镜像库,然后就可以从镜像库安装、更新或降级Docker
允许apt通过https使用镜像库
1  | root@iZ23ldh8kudZ:~# sudo apt-get install -y --no-install-recommends \  | 
添加Docker官方公钥
1  | root@iZ23ldh8kudZ:~# curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -  | 
校验公钥58118E89F3A912897C070ADBF76221572C52609D:
1  | root@iZ23ldh8kudZ:~# apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D  | 
用下面的命令去稳定你的镜像库
1  | root@iZ23ldh8kudZ:~# sudo add-apt-repository \  | 
lsb_release -cs这个子命令返回你的ubuntu系统的代号,如trusty
启用测试镜像库。通过编辑/etc/apt/sources.list,并在下面这行的最后添加testing。
deb https://apt.dockerproject.org/repo/ ubuntu-trusty main
添加后:
deb https://apt.dockerproject.org/repo/ ubuntu-trusty main testing
安装Docker
更新apt包
1  | root@iZ23ldh8kudZ:~# sudo apt-get update  | 
安装最新版docker,或者在下一步安装指定版本的
用下面的命令安装最新版
1  | root@iZ23ldh8kudZ:~# sudo apt-get -y install docker-engine  | 
在生产机器,你需要安装指定版本的docker,不要总是使用最新版,下面的命令列出了所有可用版本
1  | root@iZ23ldh8kudZ:~# apt-cache madison docker-engine  | 
每行的第二列是版本号,第三列是镜像库名,然后选择一个指定的版本进行安装。
1  | root@iZ23ldh8kudZ:~# sudo apt-get -y install docker-engine=<版本号>  | 
运行Hello World来检验是否安装正确
1  | root@iZ23ldh8kudZ:~# sudo docker run hello-world  | 
运行后报错了:
1  | Unable to find image 'hello-world:latest' locally  | 
重启docker服务:
1  | root@iZ23ldh8kudZ:~# service docker restart  | 
再次运行:
1  | root@iZ23ldh8kudZ:~# docker run hello-world  |