内核支持
如果我们使用的ubuntu系统是14.04之前的版本,我们需要先升级内核。
$ sudo apt-get update
$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
$ sudo reboot
添加GPG密钥
Docker安装
首先需要安装apt-transport-https支持和Docker库的密钥。
$ sudo apt-get install apt-transport-https ca-certificates
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
添加Docker安装源
我们需要根据自己的系统版本添加对应的docker源
$ sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
$ sudo apt-get update
各版本对应的源如下:
Ubuntu Precise 12.04 (LTS): deb https://apt.dockerproject.org/repo ubuntu-precise main
Ubuntu Trusty 14.04 (LTS): deb https://apt.dockerproject.org/repo ubuntu-trusty main
Ubuntu Wily 15.10: deb https://apt.dockerproject.org/repo ubuntu-wily main
Ubuntu Xenial 16.04 (LTS): deb https://apt.dockerproject.org/repo ubuntu-xenial main
安装
我们先查看一下当前可以安装的版本都有哪些。
$ sudo apt-cache policy docker-engine
docker-engine:
Installed: (none)
Candidate: 17.05.0~ce-0~ubuntu-trusty
Version table:
17.05.0~ce-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
17.04.0~ce-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
17.03.1~ce-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
17.03.0~ce-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
1.13.1-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
1.13.0-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
1.12.6-0~ubuntu-trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
...
接下来就可以安装特定版本的docker了,不过如果我们之前有安装过docker,首先需要删除之前安装的就版本。
# 卸载旧版docker
$ sudo apt-get purge docker docker.io lxc-docker docker-engine
$ sudo apt-get install docker-engine=17.05.0~ce-0~ubuntu-trusty
$ sudo docker -v
Docker version 17.05.0-ce, build 89658be
下载Ubuntu镜像
下载Ubuntu镜像,然后启动一个Container测试是否安装成功。
$ docker pull ubuntu
$ docker run -i -t ubuntu bash
成功之后,运行exit即可退出docker。
参考文档
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/ Docker官方文档