安装需要的软件包

yum install -y yum-utils

[root@VM-4-7-centos ~]# yum install -y yum-util
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel                                                                                                                      | 4.7 kB  00:00:00
extras                                                                                                                    | 2.9 kB  00:00:00
mysql-connectors-community                                                                                                | 2.6 kB  00:00:00
mysql-tools-community                                                                                                     | 2.6 kB  00:00:00
mysql57-community                                                                                                         | 2.6 kB  00:00:00
os                                                                                                                        | 3.6 kB  00:00:00
updates                                                                                                                   | 2.9 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                                                                                         | 247 kB  00:00:00
(2/4): epel/7/x86_64/updateinfo                                                                                           | 1.0 MB  00:00:00
(3/4): epel/7/x86_64/primary_db                                                                                           | 7.0 MB  00:00:01
(4/4): updates/7/x86_64/primary_db                                                                                        |  16 MB  00:00:01
No package yum-util available.
Error: Nothing to do

设置镜像仓库

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

[root@VM-4-7-centos ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

更新yum软件包索引

yum makecache fast

[root@VM-4-7-centos ~]# yum makecache fast
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
docker-ce-stable                                                                                                          | 3.5 kB  00:00:00
epel                                                                                                                      | 4.7 kB  00:00:00
extras                                                                                                                    | 2.9 kB  00:00:00
mysql-connectors-community                                                                                                | 2.6 kB  00:00:00
mysql-tools-community                                                                                                     | 2.6 kB  00:00:00
mysql57-community                                                                                                         | 2.6 kB  00:00:00
os                                                                                                                        | 3.6 kB  00:00:00
updates                                                                                                                   | 2.9 kB  00:00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo                                                                               |   55 B  00:00:00
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                               |  78 kB  00:00:00
Metadata Cache Created

安装docker

yum install docker-ce docker-ce-cli containerd.io

docker-cd 社区版 ee企业版本

启动docker

systemctl start docker

验证是否安装成功

docker version

[root@VM-4-7-centos ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.16
 API version:       1.41
 Go version:        go1.17.10
 Git commit:        aa7e414
 Built:             Thu May 12 09:19:45 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.16
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.10
  Git commit:       f756502
  Built:            Thu May 12 09:18:08 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.4
  GitCommit:        212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
 runc:
  Version:          1.1.1
  GitCommit:        v1.1.1-0-g52de29d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0