一、准备

  • 环境
[root@333fc545a958 ~]# uname -r
3.10.0-514.el7.x86_64
[root@333fc545a958 ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

注意:Docker 要求 CentOS 系统的内核版本不低于 3.10

二、安装

  • 卸载旧版本(如果安装过旧版本的话)
[root@333fc545a958 ~]# yum remove docker docker-common docker-selinux docker-engine
  • 安装依赖
[root@333fc545a958 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 openvswitch
  • 设置yum源
[root@333fc545a958 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • 查看仓库中所有docker版本
[root@333fc545a958 ~]# yum list docker-ce --showduplicates | sort -r
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loaded plugins: fastestmirror, langpacks
Installed Packages
docker-ce.x86_64            18.03.1.ce-1.el7.centos             installed       
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.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
Determining fastest mirrors
Available Packages
  • 安装docker
[root@333fc545a958 ~]# yum install docker-ce  #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
[root@333fc545a958 ~]# yum install <FQPN>  # 例如:yum install docker-ce-17.12.0.ce
  • 启动并加入开机启动
[root@333fc545a958 ~]# systemctl start docker
[root@333fc545a958 ~]# systemctl enable docker
  • 验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
[root@333fc545a958 ~]# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:20:16 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:58 2018
  OS/Arch:      linux/amd64
  Experimental: false

三、工具安装

  • 安装docker-compose
[root@333fc545a958 ~]# curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
[root@333fc545a958 ~]# chmod +x  /usr/local/bin/docker-compose
  • 安装ovs
[root@333fc545a958 ~]# wget http://openvswitch.org/releases/openvswitch-2.9.2.tar.gz
[root@333fc545a958 ~]# tar -xf openvswitch-2.9.2.tar.gz
[root@333fc545a958 ~]# cd openvswitch-2.9.2
[root@333fc545a958 openvswitch-2.9.2]# /.configure
[root@333fc545a958 openvswitch-2.9.2]# make && make install

提示:可以用yum安装

  • 安装ovs-docker
[root@333fc545a958 ~]# curl -L https://raw.githubusercontent.com/openvswitch/ovs/master/utilities/ovs-docker > /usr/local/bin/ovs-docker 
[root@333fc545a958 ~]# chmod +x /usr/local/bin/ovs-docker

四、错误处理

  • 缺少pigz库
[root@333fc545a958 ~]# yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.03.1.ce-1.el7.centos will be installed
--> Processing Dependency: pigz for package: docker-ce-18.03.1.ce-1.el7.centos.x86_64
--> Finished Dependency Resolution
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-stable)
           Requires: pigz
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles —nodigest
  • 安装pigz库
[root@333fc545a958 ~]# yum install http://mirror.centos.org/centos/7/extras/x86_64/Packages/pigz-2.3.3-1.el7.centos.x86_64.rpm

标签: none