本篇介紹了在Mac OS, Windows, Linux下的Docker安裝方法。linux
先來一個官方的介紹:git
Docker Engine is available for Linux (CentOS, Debian, Fedora, Oracle Linux, RHEL, SUSE, and Ubuntu) or Windows Server operating systems and is based on containerd - the open source container runtime project that Docker donated to the Cloud Native Computing Foundation (CNCF) in 2017. It is available as both a free community-supported engine and as a commercially-supported enterprise engine (Docker Engine-Enterprise) that also forms the foundation for an enterprise container platform.github
基本上全平臺已經覆蓋,英文好的同窗,能夠自取。docker
Mac OS上的Docker安裝方法方法一官方dmg:ubuntu
官方下載地址:windows
Docker Descktop for Maccentos
對系統的要求:bash
Requires Apple Mac OS Sierra 10.12 or above. Download Docker Toolbox for previous OS versions.app
只要系統是 Mac OS Sierra 10.12以上便可。curl
下載完Docker.dmg安裝包以後,雙擊便可以安裝,可能須要系統管理員權限,輸入密碼便可。
運行事後,小圖標:
圖片裂了,聯繫:lw96@live.comMac上Docker安裝運行以後
安裝完以後,在終端工具中,使用docker version來查看Docker版本。
圖片裂了,聯繫:lw96@live.comdocker版本
設置中國區加速地址:
圖片裂了,聯繫:lw96@live.comdocker加速
阿里雲加速:Docker 鏡像加速器
方法二brew cask:
brew update
brew cask install docker
brew cask uninstall docker上面的命令將會把Docker安裝在Applications目錄下。
Windows上Docker安裝官方下載地址:Docker Desktop for Windows
對系統的要求:
Requires Microsoft Windows 10 Professional or Enterprise 64-bit. For previous versions get Docker Toolbox.
須要Windows 10專業版及企業的64位版本,在Windows server 2016以上親測是可用的。Windows 8/7/Vista/Xp之類的,就別想了,老實去裝Windows 10或者虛擬機中去使用。
圖片裂了,聯繫:lw96@live.comwindows-docker安裝示例
Linux上Docker安裝Centos中Docker安裝方法先刪除舊的版本(若是沒有能夠跳過)
$ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine安裝必須的依賴:
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2添加stable的Docker-ce的源:
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo安裝docker-ce:
$ sudo yum install docker-ce docker-ce-cli containerd.io選擇指定的安裝版本(可選)
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stabledocker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable咱們來舉個例子,好比咱們要安裝3:18.09.1-3.el7這個版本,使用以下命令結構:
$ sudo yum install docker-ce- docker-ce-cli- containerd.io命令說明:
第一部分是docker-ce,第二部分是版本號18.09.1,看明白了嗎?就是這樣子:
$ sudo yum install -y docker-ce-18.09.1 docker-ce-cli-18.09.1啓動服務並測試一下:
sudo systemctl start docker
sudo docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world1b930d010525: Pull completeDigest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535Status: 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:
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://hub.docker.com/
For more examples and ideas, visit:https://docs.docker.com/get-started/若是看到上面的提示,說明Docker已經成功安裝並運行了了。
關於升級&刪除:
升級:
yum -y update
yum -y update docker-ce docker-ce-cli containerd.io刪除:
sudo yum remove docker-ce
sudo rm -rf /var/lib/dockerDebian中Docker的安裝方法刪除舊的版本(可跳過)
$ sudo apt-get remove docker docker-engine docker.io containerd runc安裝依賴:
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88uid Docker Release (CE deb)sub 4096R/F273FCD8 2017-02-22使用stable安裝源:
x86_64 / amd64armhfarm64$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"安裝docker-ce:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io安裝指定的版本:(可選)
$ apt-cache madison docker-ce
docker-ce | 5:18.09.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packagesdocker-ce | 5:18.09.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packagesdocker-ce | 18.06.1~ce~3-0~debian | https://download.docker.com/linux/debian stretch/stable amd64 Packagesdocker-ce | 18.06.0~ce~3-0~debian | https://download.docker.com/linux/debian stretch/stable amd64 Packages...安裝格式:
$ sudo apt-get install docker-ce= docker-ce-cli= containerd.io舉例說明:好比要安裝5:18.09.1~3-0~debian-stretch版本的docker的話:
$ sudo apt-get install docker-ce=18.09.1 docker-ce-cli=18.09.1 containerd.io啓動服務並測試:
$ sudo service docker start
$ sudo service docker status
$ sudo docker run hello-worldUbuntu中Docker安裝方法刪除舊的版本(可跳過)
$ sudo apt-get remove docker docker-engine docker.io containerd runc安裝依賴:
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88uid [ unknown] Docker Release (CE deb)sub rsa4096 2017-02-22 [S]使用stable安裝源:
x86_64/amd64armhfarm64ppc64le (IBM Power)s390x (IBM Z)$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"安裝docker-ce:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io安裝指定的版本:(可選)
$ apt-cache madison docker-ce
docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packagesdocker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packagesdocker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packagesdocker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages...安裝格式:
$ sudo apt-get install docker-ce= docker-ce-cli= containerd.io舉例說明:好比要安裝5:18.09.1~3-0~ubuntu-xenial版本的docker的話:
$ sudo apt-get install docker-ce=18.09.1 docker-ce-cli=18.09.1 containerd.io啓動服務並測試:
$ sudo service docker start
$ sudo service docker status
$ sudo docker run hello-worldDocker-compose集合命令Compose工具是一個批量工具,用於運行與管理多個docker容器。
官方文檔:Install Docker Compose
在Mac/Windows中,已經集成了docker-compose命令
在WindowsServer中 先啓動PowerShell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12而後運行以下命令:
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFilesDockerdocker-compose.exe而後測試一下:docker-compose --version
Linux中:
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --versiondocker-compose version 1.23.2, build 1110ad01已禁用此文檔中的部份內容