概览

整个配置大抵分为上面的步骤:

  • 查看LInux内核版本,不能太老
  • root权限更新yum
  • 清理旧版本。
  • 更换Docker镜像地址
  • 装置Docker

1. 查看Linux内核版本

倡议应用centerOs 7.9 以上的版本,内核基本上能够满足Docker的需要。

[zxd@localhost ~]$ uname -r3.10.0-1160.el7.x86_64

2. root权限更新yum

集体Linux虚拟机应用了具备sudo权限的普通用户,所以命令有些许不同。

[zxd@localhost ~]$ sudo yum -y update........

如果内核的版本低于3.1,则倡议应用上面的命令降级到最新版的内核。

yum -y update:降级所有包同时也降级软件和零碎内核;yum -y upgrade:只降级所有包,不降级软件和零碎内核

3. 清理旧版本

如果之前Linux装置过Docker,则须要先进行卸载。

卸载旧版本(如果之前装置过的话)

[zxd@localhost ~]$ sudo yum remove docker docker-common docker-selinux docker-engine[sudo] password for zxd: y[而后按回车]

4. 更换Docker镜像

如果Docker下载或者更新过慢,能够应用上面的镜像进行替换,第一个为地方镜像,第二个为阿里镜像。

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repoyum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5. 装置Docker

5.1 装置依赖包

装置须要的软件包,能够应用 yum-util 提供yum-config-manager性能。咱们能够执行上面的命令:

[zxd@localhost ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2[sudo] password for zxd: 
提醒:device-mapper-persistent-data lvm2是驱动所须要的依赖

5.2 抉择docker版本并装置

应用上面的命令抉择适合的版本装置。

> yum list docker-ce --showduplicates | sort -r * updates: mirrors.aliyun.comThis system is not registered with an entitlement server. You can use subscription-manager to register.              : managerLoading mirror speeds from cached hostfileLoaded plugins: fastestmirror, product-id, search-disabled-repos, subscription- * extras: mirrors.aliyun.comdocker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stabledocker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stabledocker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stabledocker-ce.x86_64            3:20.10.6-3.el7                     docker-ce-stabledocker-ce.x86_64            3:20.10.5-3.el7                     docker-ce-stable......docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stabledocker-ce.x86_64            18.06.2.ce-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-stabledocker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stabledocker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable

这抉择了18.03.1.ce-1.el7.centos版本进行装置,具体的装置命令如下:

yum -y install docker-ce-18.03.1.ce

具体的运行日志如下,如果呈现相似上面的日志,阐明装置胜利

setsebool:  SELinux is disabled.  Installing : pigz-2.3.3-1.el7.centos.x86_64                                                                                                                                                                                                                 2/4   Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                                                                                                                             3/4   Installing : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                                                                                                                       4/4   Verifying  : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                                                                                                                                                                             1/4   Verifying  : pigz-2.3.3-1.el7.centos.x86_64                                                                                                                                                                                                                 2/4   Verifying  : docker-ce-18.03.1.ce-1.el7.centos.x86_64                                                                                                                                                                                                       3/4   Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                                                                                                             4/4 Installed:  docker-ce.x86_64 0:18.03.1.ce-1.el7.centos                                                                                                                                                                                                                      Dependency Installed:  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                                              libtool-ltdl.x86_64 0:2.4.2-22.el7_3                                              pigz.x86_64 0:2.3.3-1.el7.centos                                             Complete!

5.3 开机自启

为了不便能够设置开机自启,当然也能够手动开启

# 开机启动systemctl start docker# 进行dockersystemctl stop docker# 主动启动dockersytemctl enable docker

操作过程如下:

[zxd@localhost ~]$ sudo systemctl enable dockerCreated symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.