原文: http://www.itmuch.com/docker/02-docker-install/
2.1 CentOS
2.1.1 系統要求
- CentOS 7或更高版本
-
倉庫必須處于啟用狀态,該倉庫預設啟用,但如果您禁用了該倉庫,請按照 https://wiki.centos.org/AdditionalResources/Repositories 中的描述重新啟用。centos-extras
- 建議使用
存儲驅動overlay2
2.1.2 yum安裝
2.1.2.1 解除安裝老版本的Docker
在CentOS中,老版本Docker名稱是
docker
或
docker-engine
,而Docker CE的軟體包名稱是
docker-ce
。是以,如已安裝過老版本的Docker,需使用如下指令解除安裝。
sudo yum remove docker \
docker-common \
docker-selinux \
docker-engine
需要注意的是,執行該指令隻會解除安裝Docker本身,而不會删除Docker存儲的檔案,例如鏡像、容器、卷以及網絡檔案等。這些檔案儲存在
/var/lib/docker
目錄中,需要手動删除。
2.1.2.2 安裝倉庫
- 執行以下指令,安裝Docker所需的包。其中,
提供了yum-utils
工具;yum-config-manager
及device-mapper-persistent-data
則是lvm2
存儲驅動所需的包。devicemapper
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 執行如下指令,安裝
倉庫。必須安裝stable
倉庫,即使你想安裝stable
edge
倉庫中的Docker建構版本。test
sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
- [可選] 執行如下指令,啟用
edge
倉庫。edge/test倉庫其實也包含在了test
檔案中,但預設是禁用的,可使用以下指令來啟用。docker.repo
如需再次禁用,可加上sudo yum-config-manager --enable docker-ce-edge # 啟用edge倉庫 sudo yum-config-manager --enable docker-ce-test # 啟用test倉庫
标簽。例如,執行如下指令即可禁用edge倉庫。--disable
TIPS:從Docker 17.06起,stable版本也會釋出到edge以及test倉庫中。sudo yum-config-manager --disable docker-ce-edge
2.1.2.3 安裝Docker CE
- 執行以下指令,更新
的包索引yum
sudo yum makecache fast
- 執行如下指令即可安裝最新版本的Docker CE
sudo yum install docker-ce
- 在生産環境中,可能需要指定想要安裝的版本,此時可使用如下指令列出目前可用的Docker版本。
這樣,列出版本後,可使用如下指令,安裝想要安裝的Docker CE版本。yum list docker-ce.x86_64 --showduplicates | sort -r
sudo yum install docker-ce-<VERSION>
- 啟動Docker
sudo systemctl start docker
- 驗證安裝是否正确。
這樣,Docker将會下載下傳測試鏡像,并使用該鏡像啟動一個容器。如能夠看到類似如下的輸出,則說明安裝成功。sudo docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f Status: Downloaded newer image for hello-world:latest 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. 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/
2.1.2.4 更新Docker CE
如需更新Docker CE,隻需執行如下指令:
sudo yum makecache fast
然後按照安裝Docker的步驟,即可更新Docker。
2.1.2.5 參考文檔
CentOS 7安裝Docker官方文檔:
https://docs.docker.com/engine/installation/linux/docker-ce/centos/,文檔中還講解了在CentOS 7中安裝Docker CE的其他方式,本文不作贅述。
2.1.3 shell一鍵安裝
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
搞定一切。
2.2 Ubuntu
2.2.1 系統要求
- Docker支援以下版本的Ubuntu,要求64位。
- Zesty 17.04
- Xenial 16.04 (LTS)
- Trusty 14.04 (LTS)
- 支援運作的平台:
、x86_64
armhf
。其中,如選擇IBM Z,那麼隻支援Ubuntu Xenial以及Zesty。s390x(IBM Z)
- 本文使用Ubuntu 16.04 LTS,下載下傳位址: http://cn.ubuntu.com/download/
2.2.2 安裝步驟
2.2.2.1 解除安裝老版本Docker
在Ubuntu中,老版本的軟體包名稱是
docker
或者
docker-engine
docker-ce
。是以,如已安裝過老版本的Docker,需要先解除安裝掉。執行以下指令,即可解除安裝老版本的Docker及其依賴。
sudo apt-get remove docker docker-engine docker.io
需要注意的是,執行該指令隻會解除安裝Docker本身,而不會删除Docker内容,例如鏡像、容器、卷以及網絡。這些檔案儲存在
/var/lib/docker
2.2.2.2 Ubuntu Trusty 14.04 額外建議安裝的包
除非你有不得已的苦衷,否則強烈建議安裝
linux-image-extra-*
軟體包,以便于Docker使用
aufs
存儲驅動。執行如下指令,即可安裝
linux-image-extra-*
。
sudo apt-get update
sudo apt-get install \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
對于Ubuntu 16.04或更高版本,Linux核心包含了對OverlayFS的支援,Docker CE預設會使用
overlay2
存儲驅動。
2.2.2.3 安裝倉庫
- 執行如下指令,更新
的包索引。apt
sudo apt-get update
- 執行如下指令,進而允許
使用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 -
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
-
倉庫。無論如何都必須安裝stable
stable
edge
倉庫中的Docker建構。如需添加test
edge
倉庫,可在如下指令中的“stable" 後,添加test
edge
test
或兩者。請視自己Ubuntu所運作的平台來執行如下指令。
NOTE:如下指令中的
子指令用于傳回您Ubuntu的發行版名稱,例如lsb_release -cs
。有時,在例如Linux Mint這樣的發行版中,您可能需要将如下指令中的xenial
更改為系統的父級Ubuntu發行版。例如,如果您使用的是Linux Mint Rafaela,則可以使用$(lsb_release -cs)
amd64:trusty
armhf:$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
s390x:$ sudo add-apt-repository \ "deb [arch=armhf] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
NOTE:從Docker 17.06起,stable版本也會釋出到edge以及test倉庫中。$ sudo add-apt-repository \ "deb [arch=s390x] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
2.2.2.4 安裝Docker CE
-
包索引。apt
sudo apt-get update
- 執行如下指令,即可安裝最新版本的Docker CE。任何已存在的Docker将會被覆寫安裝。
WARNING:如啟用了多個Docker倉庫,使用指令apt-get install 或apt-get update 指令安裝或更新時,如未指定版本,那麼将會安裝最新的版本。這可能不适合您的穩定性要求。sudo apt-get install docker-ce
- 在生産環境中,我們可能需要指定想要安裝的版本,此時可使用如下指令列出目前可用的Docker版本。
apt-cache madison docker-ce
Docker daemon會自動啟動。sudo apt-get install docker-ce=<VERSION>
-
sudo docker run hello-world
2.2.2.5 更新Docker CE
sudo apt-get update
2.2.2.6 參考文檔
Ubuntu安裝Docker官方文檔:
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/,文檔還講解了在Ubuntu中安裝Docker CE的其他方式,本文不作贅述。
2.3 macOS
2.3.1 系統要求
macOS Yosemite 10.10.3或更高版本
2.3.2 安裝步驟
- 前往 https://store.docker.com/editions/community/docker-ce-desktop-mac ,點選頁面右側的“Get Docker”按鈕,下載下傳安裝包;
- 輕按兩下即可安裝。
2.4 Windows(docker for windows)
2.4.1 系統要求
Windows 10 Professional 或 Windows 10 Enterprise X64
對于Win 7,可使用Docker Toolbox(不建議使用)
2.4.2 安裝步驟
2.5 其他系統
詳見官方文檔:
https://docs.docker.com/engine/installation/2.6 加速安裝
注冊阿裡雲,參考該頁面的内容安裝即可:
https://cr.console.aliyun.com/#/accelerator