Centos7.9 安裝 Docker

gui.h發表於2024-09-23

由於docker被封,直接使用docker官方的教程安裝會被牆,所以使用阿里雲的源進行安裝
參考文件:https://help.aliyun.com/zh/ecs/use-cases/install-and-use-docker-on-a-linux-ecs-instance

安裝Docker

  1. 執行以下命令,下載docker-ce的yum源。
sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  1. 執行以下命令,安裝Docker。
sudo yum -y install docker-ce

遇到的問題

1. 依賴問題 container-selinux >= 2:2.74

[root@VMS-WL001131 ~]#y yum -y install docker-ce                           
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:26.1.4-1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: containerd.io >= 1.6.24 for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.33-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.33-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:26.1.4-1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-26.1.4-1.el7.x86_64
---> Package docker-ce-cli.x86_64 1:26.1.4-1.el7 will be installed
--> Processing Dependency: docker-buildx-plugin for package: 1:docker-ce-cli-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-compose-plugin for package: 1:docker-ce-cli-26.1.4-1.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
---> Package libseccomp.x86_64 0:2.3.1-4.el7 will be installed
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.33-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.33-3.1.el7.x86_64
---> Package docker-buildx-plugin.x86_64 0:0.14.1-1.el7 will be installed
---> Package docker-ce.x86_64 3:26.1.4-1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-26.1.4-1.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
---> Package docker-compose-plugin.x86_64 0:2.27.1-1.el7 will be installed
--> Finished Dependency Resolution
Error: Package: containerd.io-1.6.33-3.1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
           Requires: slirp4netns >= 0.4
Error: Package: 3:docker-ce-26.1.4-1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
           Requires: fuse-overlayfs >= 0.7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

下載安裝container-selinux

https://linuxsoft.cern.ch/cern/centos/7/extras/x86_64/repoview/container-selinux.html
滑鼠右鍵超連結,複製需要下載的rpm地址

wget https://linuxsoft.cern.ch/cern/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm
rpm -ivh container-selinux-2.107-3.el7.noarch.rpm

再次遇到問題了,如果你沒遇到就跳過

[root@VMS-WL001131 ~]# rpm -ivh container-selinux-2.107-3.el7.noarch.rpm 
warning: container-selinux-2.107-3.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
        policycoreutils-python is needed by container-selinux-2:2.107-3.el7.noarch

安裝policycoreutils-python

[root@VMS-WL001131 ~]# yum install policycoreutils-python
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfil

源有問題,配置阿里雲源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum clean all
yum makecache

重試安裝 policycoreutils-python

[root@VMS-WL001131 ~]# yum install policycoreutils-python
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libcgroup for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================
 Package                                                             Arch                                                Version                                                    Repository                                         Size
============================================================================================================================================================================================================================================
Installing:
 policycoreutils-python                                              x86_64                                              2.5-34.el7                                                 base                                              457 k
Installing for dependencies:
 audit-libs-python                                                   x86_64                                              2.8.5-4.el7                                                base                                               76 k
 checkpolicy                                                         x86_64                                              2.5-8.el7                                                  base                                              295 k
 libcgroup                                                           x86_64                                              0.41-21.el7                                                base                                               66 k
 libsemanage-python                                                  x86_64                                              2.5-14.el7                                                 base                                              113 k
 python-IPy                                                          noarch                                              0.75-6.el7                                                 base                                               32 k
 setools-libs                                                        x86_64                                              3.3.8-4.el7                                                base                                              620 k

Transaction Summary
============================================================================================================================================================================================================================================
Install  1 Package (+6 Dependent packages)

Total download size: 1.6 M
Installed size: 5.3 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/audit-libs-python-2.8.5-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for audit-libs-python-2.8.5-4.el7.x86_64.rpm is not installed
(1/7): audit-libs-python-2.8.5-4.el7.x86_64.rpm                                                                                                                                                                      |  76 kB  00:00:00     
(2/7): libcgroup-0.41-21.el7.x86_64.rpm                                                                                                                                                                              |  66 kB  00:00:00     
(3/7): checkpolicy-2.5-8.el7.x86_64.rpm                                                                                                                                                                              | 295 kB  00:00:00     
(4/7): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                                                                                                                      | 113 kB  00:00:00     
(5/7): policycoreutils-python-2.5-34.el7.x86_64.rpm                                                                                                                                                                  | 457 kB  00:00:00     
(6/7): python-IPy-0.75-6.el7.noarch.rpm                                                                                                                                                                              |  32 kB  00:00:00     
(7/7): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                                                                                                                           | 620 kB  00:00:00     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       4.5 MB/s | 1.6 MB  00:00:00     
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 From       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libcgroup-0.41-21.el7.x86_64                                                                                                                                                                                             1/7 
  Installing : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                                                                          2/7 
  Installing : audit-libs-python-2.8.5-4.el7.x86_64                                                                                                                                                                                     3/7 
  Installing : python-IPy-0.75-6.el7.noarch                                                                                                                                                                                             4/7 
  Installing : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                                                                     5/7 
  Installing : checkpolicy-2.5-8.el7.x86_64                                                                                                                                                                                             6/7 
  Installing : policycoreutils-python-2.5-34.el7.x86_64                                                                                                                                                                                 7/7 
  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                                                                                                                                                             1/7 
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                                                                     2/7 
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                                                                                                                                             3/7 
  Verifying  : policycoreutils-python-2.5-34.el7.x86_64                                                                                                                                                                                 4/7 
  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                                                                                                                                                                                     5/7 
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                                                                          6/7 
  Verifying  : libcgroup-0.41-21.el7.x86_64                                                                                                                                                                                             7/7 

Installed:
  policycoreutils-python.x86_64 0:2.5-34.el7                                                                                                                                                                                                

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7      checkpolicy.x86_64 0:2.5-8.el7      libcgroup.x86_64 0:0.41-21.el7      libsemanage-python.x86_64 0:2.5-14.el7      python-IPy.noarch 0:0.75-6.el7      setools-libs.x86_64 0:3.3.8-4.el7     

Complete!
[root@VMS-WL001131 ~]# rpm -ivh container-selinux-2.107-3.el7.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:container-selinux-2:2.107-3.el7  ################################# [100%]
[root@VMS-WL001131 ~]#  yum -y install docker-ce                     
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:26.1.4-1.el7 will be installed
--> Processing Dependency: containerd.io >= 1.6.24 for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-26.1.4-1.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.33-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:26.1.4-1.el7 will be installed
--> Processing Dependency: docker-buildx-plugin for package: 1:docker-ce-cli-26.1.4-1.el7.x86_64
--> Processing Dependency: docker-compose-plugin for package: 1:docker-ce-cli-26.1.4-1.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-26.1.4-1.el7.x86_64
---> Package libseccomp.x86_64 0:2.3.1-4.el7 will be installed
--> Running transaction check
---> Package docker-buildx-plugin.x86_64 0:0.14.1-1.el7 will be installed
---> Package docker-compose-plugin.x86_64 0:2.27.1-1.el7 will be installed
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================
 Package                                                            Arch                                            Version                                                 Repository                                                 Size
============================================================================================================================================================================================================================================
Installing:
 docker-ce                                                          x86_64                                          3:26.1.4-1.el7                                          docker-ce-stable                                           27 M
Installing for dependencies:
 containerd.io                                                      x86_64                                          1.6.33-3.1.el7                                          docker-ce-stable                                           35 M
 docker-buildx-plugin                                               x86_64                                          0.14.1-1.el7                                            docker-ce-stable                                           14 M
 docker-ce-cli                                                      x86_64                                          1:26.1.4-1.el7                                          docker-ce-stable                                           15 M
 docker-ce-rootless-extras                                          x86_64                                          26.1.4-1.el7                                            docker-ce-stable                                          9.4 M
 docker-compose-plugin                                              x86_64                                          2.27.1-1.el7                                            docker-ce-stable                                           13 M
 fuse-overlayfs                                                     x86_64                                          0.7.2-6.el7_8                                           extras                                                     54 k
 fuse3-libs                                                         x86_64                                          3.6.1-4.el7                                             extras                                                     82 k
 libseccomp                                                         x86_64                                          2.3.1-4.el7                                             base                                                       56 k
 slirp4netns                                                        x86_64                                          0.4.3-4.el7_8                                           extras                                                     81 k

Transaction Summary
============================================================================================================================================================================================================================================
Install  1 Package (+9 Dependent packages)

Total download size: 114 M
Installed size: 402 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY                                           ] 9.8 MB/s |  15 MB  00:00:10 ETA 
Public key for docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm is not installed
(1/10): docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm                                                                                                                                                                 |  14 MB  00:00:00     
(2/10): docker-ce-26.1.4-1.el7.x86_64.rpm                                                                                                                                                                            |  27 MB  00:00:01     
(3/10): containerd.io-1.6.33-3.1.el7.x86_64.rpm                                                                                                                                                                      |  35 MB  00:00:02     
(4/10): docker-ce-rootless-extras-26.1.4-1.el7.x86_64.rpm                                                                                                                                                            | 9.4 MB  00:00:00     
(5/10): docker-ce-cli-26.1.4-1.el7.x86_64.rpm                                                                                                                                                                        |  15 MB  00:00:00     
(6/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                                                                                                                                            |  82 kB  00:00:00     
(7/10): libseccomp-2.3.1-4.el7.x86_64.rpm                                                                                                                                                                            |  56 kB  00:00:00     
(8/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                                                                                                                                      |  54 kB  00:00:00     
(9/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                                                                                                                                         |  81 kB  00:00:00     
(10/10): docker-compose-plugin-2.27.1-1.el7.x86_64.rpm                                                                                                                                                               |  13 MB  00:00:00     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                        26 MB/s | 114 MB  00:00:04     
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : libseccomp-2.3.1-4.el7.x86_64                                                                                                                                                                                           1/10 
  Installing : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                                                                                        2/10 
  Installing : containerd.io-1.6.33-3.1.el7.x86_64                                                                                                                                                                                     3/10 
  Installing : docker-buildx-plugin-0.14.1-1.el7.x86_64                                                                                                                                                                                4/10 
  Installing : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                                                                                           5/10 
  Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                                                                                     6/10 
  Installing : docker-compose-plugin-2.27.1-1.el7.x86_64                                                                                                                                                                               7/10 
  Installing : 1:docker-ce-cli-26.1.4-1.el7.x86_64                                                                                                                                                                                     8/10 
  Installing : docker-ce-rootless-extras-26.1.4-1.el7.x86_64                                                                                                                                                                           9/10 
  Installing : 3:docker-ce-26.1.4-1.el7.x86_64                                                                                                                                                                                        10/10 
  Verifying  : docker-compose-plugin-2.27.1-1.el7.x86_64                                                                                                                                                                               1/10 
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                                                                                           2/10 
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                                                                                     3/10 
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                                                                                        4/10 
  Verifying  : containerd.io-1.6.33-3.1.el7.x86_64                                                                                                                                                                                     5/10 
  Verifying  : libseccomp-2.3.1-4.el7.x86_64                                                                                                                                                                                           6/10 
  Verifying  : 3:docker-ce-26.1.4-1.el7.x86_64                                                                                                                                                                                         7/10 
  Verifying  : 1:docker-ce-cli-26.1.4-1.el7.x86_64                                                                                                                                                                                     8/10 
  Verifying  : docker-ce-rootless-extras-26.1.4-1.el7.x86_64                                                                                                                                                                           9/10 
  Verifying  : docker-buildx-plugin-0.14.1-1.el7.x86_64                                                                                                                                                                               10/10 

Installed:
  docker-ce.x86_64 3:26.1.4-1.el7                                                                                                                                                                                                           

Dependency Installed:
  containerd.io.x86_64 0:1.6.33-3.1.el7      docker-buildx-plugin.x86_64 0:0.14.1-1.el7      docker-ce-cli.x86_64 1:26.1.4-1.el7      docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7      docker-compose-plugin.x86_64 0:2.27.1-1.el7     
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8      fuse3-libs.x86_64 0:3.6.1-4.el7                 libseccomp.x86_64 0:2.3.1-4.el7          slirp4netns.x86_64 0:0.4.3-4.el7_8                  

Complete!
[root@VMS-WL001131 ~]# systemctl start docker
[root@VMS-WL001131 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@VMS-WL001131 ~]# docker -v
Docker version 26.1.4, build 5650f9b

相關文章