从2017年3月开始,Docker开始分为社区版本和企业版,也就是Docker CE和Docker EE, 原来Ubuntu14.04下,经过sudo apt-get install docker.io
来进行安装的方式已通过时了。在这里,会详细介绍如何在ubuntu14.04 LTS下安装Docker社区版,也就是Docker CE。linux
在开始以前,请确保你先作好一些前期准备工做,而后开始安装Docker。docker
安装Docker CE,你须要如下其中一种64位的Ubuntu操做系统:shell
Docker CE 被容许安装上在 x86_64
,armhf
, 以及 s390x
(IBM z Systems) 架构之上的Ubuntu操做系统。ubuntu
旧版本的Docker,一般叫作docker
或是docker-engine
,若是他们以前被安装在操做系统中,请先进行卸载:bash
$ sudo apt-get remove docker docker-engine docker.io
使用apt-get
查看是否还有相关包,若是没有则表示清理成功。架构
Docker CE有多种不一样的安装模式:app
当你第一次在一台全新机器上安装Docker CE以前,你须要先设置一下Docker的repositories。而后才能够从repositories中进行安装或升级Docker的操做。curl
apt
源的索引信息:$ sudo apt-get update
apt
经过HTTPS来访问repository:$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
经过使用apt-key finger print
搜索指纹码最后8位,能够验证你在上一步所生成的指纹码应该为9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
ide
$ 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"
apt
源的索引信息:$ sudo apt-get update
sudo apt-get install docker-ce
当有多个Docker的repository库的时候?
当你的机器上有多个可用的Docker repository。若是使用apt-get install
或是apt-get update
命令进行安装或更新操做的时候,没有指定安装的Docker版本,将老是安装这些repository中能支持的最高版本的Docker,这时请注意这是否你真正须要的版本。若是不是,请在安装时指定版本。post
$ apt-cache madison docker-ce docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
命令返回结果中列举的内容依赖于系统中存在的repository,能够从返回结果中选取指定版本号来安装Docker CE。第二列是版本信息。第三列是repository的名字,标识了安装包来自于那个repository,以及当前版本的稳定性。若是要安装指定版本,把版本号添加到包名字(这里包名就是docker-ce)的后面,用(=
)分隔开:
$ sudo apt-get install docker-ce=<VERSION>
安装完成后,Docker daemon(Docker服务端守护进程)会自动开始运行。
hello-world
image来验证一下安装是否正确:$ sudo docker run hello-world
运行这个命令,自动下载一个测试image,而后运行在一个container中。运行后,会打印一个消息,而后自动退出。
Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
Docker CE安装完成后,docker
group会被自动建立,可是默认没有user在里面。因此你仍然须要使用sudo
来启动和运行Docker命令。能够配置Linux postinstall来容许非受权用户运行和配置Docker CE。
若是须要升级Docker CE,首先请运行sudo apt-get update
,而后安装上文所述的安装步骤,从新选择新的Docker CE版原本进行安装。
经过repository来安装Docker CE的方法到这里就结束了,下一篇会继续介绍经过package和脚原本安装Docker CE。