系统要求cenos7以上
step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Step 3: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
Step 4: 开启Docker服务
systemctl start docker
注意:
官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
vim /etc/yum.repos.d/docker-ee.repo
将[docker-ce-test]下方的enabled=0修改为enabled=1
安装指定版本的Docker-CE:
Step 1: 查找Docker-CE的版本:
yum list docker-ce.x86_64 --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: branch, fastestmirror, langpacks
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Available Packages
Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
sudo yum -y install docker-ce-[VERSION]
安装校验
root@iZbp12adskpuoxodbkqzjfZ:$ docker version
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 07:52:04 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.0-ce
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 07:52:04 2017
OS/Arch: linux/amd64
Experimental: false
使用加速器可以提升获取Docker官方镜像的速度
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["加速地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Docker-Compose安装
使用pip
-
安装pip
yum -y install epel-release yum -y install python-pip
-
确认版本
pip --version
-
更新pip
pip install --upgrade pip
-
安装docker-compose
pip install docker-compose
-
查看版本
docker-compose version
-
安装补全工具: 为了方便输入命令,也可以安装Docker的补全提示工具帮忙快速输入命令
yum install bash-completion
配置补全工具
安装成功后,得到文件为 /usr/share/bash-completion/bash_completion,如果没有这个文件,则说明系统上没有安装这个工具。
启用脚本
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
异常问题:
ImportError: ‘module’ object has no attribute ‘check_specifier’
----------------------------------------
ERROR: Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-aXW8HB/pycparser/
解决方法:
更新setuptools工具
pip install --upgrade setuptools
异常问题:
pip安装后报“ReadTimeoutError: HTTPSConnectionPool(host=‘pypi.python.org’, port=443): Read timed out”这是由于下载延迟导致,可以采用“pip --default-timeout=200 install -U docker-compose”。
pip安装报类似” pkg_resources.DistributionNotFound: backports.ssl-match-hostname>=3.5”错误
解决方法:
执行“pip install --upgrade backports.ssl_match_hostname
”即可完成backports.ssl-match-hostname的更新。
异常问题:
pip安装报类似” Cannot uninstall ‘requests’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall” 错误
解决方法:
请” sudo pip install --ignore-installed requests
”更新模块,.
异常问题:
pip安装报类似” ipapython 4.5.4 has requirement dnspython>=1.15, but you’ll have dnspython 1.12.0 which is incompatible” 错误
解决方法:
请” pip install psutil
”
异常问题:
pip安装报类似” Command “/usr/bin/python2 -u -c “import setuptools, tokenize;file=’/tmp/pip-install-Y6TDnU/psutil/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-record-pVb4Xe/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-install-Y6TDnU/psutil/”错误,
解决方法:
请” yum install python-devel
”
下载Docker-Compose安装
sudo curl -L https://github.com/docker/compose/releases/download/1.23.0-rc3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
安装Docker-Compose:
sudo chmod +x /usr/local/bin/docker-compose
查看版本 :
docker-compose version
参考来源:
阿里docker文档
https://help.aliyun.com/document_detail/60742.html?spm=a2c4g.11186623.6.548.e74c1e66ctn9qw
51cto博客
https://blog.51cto.com/9291927/2310444