從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。