本篇介绍了在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已禁用此文档中的部份内容