最近需要搭一套Docker环境,因为需要用到Kubernetes 1.9,Kubernetes和docker的版本有对应关系,所以Docker的版本要选择Kubernetes 1.9能支持版本,我这里选择了docker-ce-17.03.2.ce-1.el7.centos,搭建方式有两种,分别是离线和在线搭建。
Kubernetes 1.9支持的docker版本【https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.9.md#external-dependencies】

image.png
Docker在线搭建
首先先通过命令【yum list docker-ce --showduplicates | sort -r】查看有没有可用的Docker镜像。

查看docker可安装版本.png
What a pity!没有发现可用的镜像,这是因为没有配置镜像仓库,可以下载阿里的镜像配置,【curl -o /etc/yum.repos.d/Docker-ce-Ali.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo】:

下载Docker CE阿里镜像配置.png
再次运行【yum list docker-ce --showduplicates | sort -r】查看可用的Docker镜像

image.png
安装17.03.2.ce-1.el7.centos版本的Docker,运行命令【yum install docker-ce-17.03.2.ce-1.el7.centos -y】,出现错误,需要安装依赖包【docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch】:

image.png
有两种方式解决,一种是去官网( https://download.docker.com/linux/centos/7/x86_64/stable/Packages/)下载下来离线安装;另外一种就是通过yum命令来安装,但是这里切记不能单独安装,否则会自动安装最新版本的Docker,这里需要和docker一起安装,运行这个命令【yum install --setopt=obsoletes=0 docker-ce-17.03.2.ce-1.el7.centos docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch】:

安装Docker.png
启动Docker
运行命令【systemctl start docker】启动docker,运行命令【systemctl status docker】查看docker运行状态

启动Docker.png
使用命令【docker info】查看Docker基本信息

docker info.png
设置Docker开机启动【systemctl enable docker.service】:

设置Docker开机启动.png
Docker离线搭建
到官网(https://download.docker.com/linux/centos/7/x86_64/stable/Packages/)下载安装包。

image.png
然后使用命令【rpm -ivh xxx.rpm】进行安装,这里没有试验过,不知道会不会有坑。