Docker在centos7.4的yum安装

参考:https://www.runoob.com/docker/centos-docker-install.html
参考:https://docs.docker.com/install/linux/docker-ce/centos/

1.卸载旧版本

[root@localhost ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
Loaded plugins: fastestmirror, langpacks
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
[root@localhost ~]# 

2.安装 Docker Engine-Community

docker官方rpm下载地址: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

使用 Docker 仓库进行安装

设置仓库
安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2
yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost tmp]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
base                                                                                          | 3.6 kB  00:00:00     
extras                                                                                        | 2.9 kB  00:00:00     
updates                                                                                       | 2.9 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                             | 164 kB  00:00:00     
(2/4): base/7/x86_64/primary_db                                                               | 6.0 MB  00:00:04     
(3/4): updates/7/x86_64/primary_db                                                            | 7.5 MB  00:00:05     
(4/4): base/7/x86_64/group_gz                                                                 | 165 kB  00:00:10     
Determining fastest mirrors
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.7.0-0.1.rc6.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.8.5-1.el7 will be an update
---> Package lvm2.x86_64 7:2.02.171-8.el7 will be updated
---> Package lvm2.x86_64 7:2.02.185-2.el7_7.2 will be an update
--> Processing Dependency: lvm2-libs = 7:2.02.185-2.el7_7.2 for package: 7:lvm2-2.02.185-2.el7_7.2.x86_64
--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_141)(64bit) for package: 7:lvm2-2.02.185-2.el7_7.2.x86_64
---> Package yum-utils.noarch 0:1.1.31-42.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-52.el7 will be an update
--> Running transaction check
---> Package device-mapper-libs.x86_64 7:1.02.140-8.el7 will be updated
--> Processing Dependency: device-mapper-libs = 7:1.02.140-8.el7 for package: 7:device-mapper-1.02.140-8.el7.x86_64
---> Package device-mapper-libs.x86_64 7:1.02.158-2.el7_7.2 will be an update
---> Package lvm2-libs.x86_64 7:2.02.171-8.el7 will be updated
---> Package lvm2-libs.x86_64 7:2.02.185-2.el7_7.2 will be an update
--> Processing Dependency: device-mapper-event = 7:1.02.158-2.el7_7.2 for package: 7:lvm2-libs-2.02.185-2.el7_7.2.x86_64
--> Running transaction check
---> Package device-mapper.x86_64 7:1.02.140-8.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.158-2.el7_7.2 will be an update
---> Package device-mapper-event.x86_64 7:1.02.140-8.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.158-2.el7_7.2 will be an update
--> Processing Dependency: device-mapper-event-libs = 7:1.02.158-2.el7_7.2 for package: 7:device-mapper-event-1.02.158-2.el7_7.2.x86_64
--> Running transaction check
---> Package device-mapper-event-libs.x86_64 7:1.02.140-8.el7 will be updated
---> Package device-mapper-event-libs.x86_64 7:1.02.158-2.el7_7.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                                  Arch              Version                         Repository          Size
=====================================================================================================================
Updating:
 device-mapper-persistent-data            x86_64            0.8.5-1.el7                     base               423 k
 lvm2                                     x86_64            7:2.02.185-2.el7_7.2            updates            1.3 M
 yum-utils                                noarch            1.1.31-52.el7                   base               121 k
Updating for dependencies:
 device-mapper                            x86_64            7:1.02.158-2.el7_7.2            updates            294 k
 device-mapper-event                      x86_64            7:1.02.158-2.el7_7.2            updates            190 k
 device-mapper-event-libs                 x86_64            7:1.02.158-2.el7_7.2            updates            189 k
 device-mapper-libs                       x86_64            7:1.02.158-2.el7_7.2            updates            322 k
 lvm2-libs                                x86_64            7:2.02.185-2.el7_7.2            updates            1.1 M

Transaction Summary
=====================================================================================================================
Upgrade  3 Packages (+5 Dependent packages)

Total download size: 3.9 M
Downloading packages:
No Presto metadata available for base
No Presto metadata available for updates
warning: /var/cache/yum/x86_64/7/updates/packages/device-mapper-event-libs-1.02.158-2.el7_7.2.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for device-mapper-event-libs-1.02.158-2.el7_7.2.x86_64.rpm is not installed
(1/8): device-mapper-event-libs-1.02.158-2.el7_7.2.x86_64.rpm                                 | 189 kB  00:00:00     
(2/8): device-mapper-libs-1.02.158-2.el7_7.2.x86_64.rpm                                       | 322 kB  00:00:00     
(3/8): lvm2-2.02.185-2.el7_7.2.x86_64.rpm                                                     | 1.3 MB  00:00:00     
(4/8): device-mapper-1.02.158-2.el7_7.2.x86_64.rpm                                            | 294 kB  00:00:01     
Public key for device-mapper-persistent-data-0.8.5-1.el7.x86_64.rpm is not installed 643 kB/s | 2.9 MB  00:00:01 ETA 
(5/8): device-mapper-persistent-data-0.8.5-1.el7.x86_64.rpm                                   | 423 kB  00:00:01     
(6/8): lvm2-libs-2.02.185-2.el7_7.2.x86_64.rpm                                                | 1.1 MB  00:00:00     
(7/8): yum-utils-1.1.31-52.el7.noarch.rpm                                                     | 121 kB  00:00:00     
(8/8): device-mapper-event-1.02.158-2.el7_7.2.x86_64.rpm                                      | 190 kB  00:00:05     
---------------------------------------------------------------------------------------------------------------------
Total                                                                                672 kB/s | 3.9 MB  00:00:05     
Retrieving key from file:///etc/pki/rpm-gpg/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
 Package    : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 7:device-mapper-libs-1.02.158-2.el7_7.2.x86_64                                                   1/16 
  Updating   : 7:device-mapper-1.02.158-2.el7_7.2.x86_64                                                        2/16 
  Updating   : 7:device-mapper-event-libs-1.02.158-2.el7_7.2.x86_64                                             3/16 
  Updating   : 7:device-mapper-event-1.02.158-2.el7_7.2.x86_64                                                  4/16 
  Updating   : 7:lvm2-libs-2.02.185-2.el7_7.2.x86_64                                                            5/16 
  Updating   : device-mapper-persistent-data-0.8.5-1.el7.x86_64                                                 6/16 
  Updating   : 7:lvm2-2.02.185-2.el7_7.2.x86_64                                                                 7/16 
  Updating   : yum-utils-1.1.31-52.el7.noarch                                                                   8/16 
  Cleanup    : 7:lvm2-2.02.171-8.el7.x86_64                                                                     9/16 
  Cleanup    : yum-utils-1.1.31-42.el7.noarch                                                                  10/16 
  Cleanup    : 7:lvm2-libs-2.02.171-8.el7.x86_64                                                               11/16 
  Cleanup    : 7:device-mapper-event-1.02.140-8.el7.x86_64                                                     12/16 
  Cleanup    : 7:device-mapper-event-libs-1.02.140-8.el7.x86_64                                                13/16 
  Cleanup    : 7:device-mapper-libs-1.02.140-8.el7.x86_64                                                      14/16 
  Cleanup    : 7:device-mapper-1.02.140-8.el7.x86_64                                                           15/16 
  Cleanup    : device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64                                          16/16 
  Verifying  : 7:device-mapper-1.02.158-2.el7_7.2.x86_64                                                        1/16 
  Verifying  : 7:lvm2-2.02.185-2.el7_7.2.x86_64                                                                 2/16 
  Verifying  : device-mapper-persistent-data-0.8.5-1.el7.x86_64                                                 3/16 
  Verifying  : yum-utils-1.1.31-52.el7.noarch                                                                   4/16 
  Verifying  : 7:device-mapper-libs-1.02.158-2.el7_7.2.x86_64                                                   5/16 
  Verifying  : 7:lvm2-libs-2.02.185-2.el7_7.2.x86_64                                                            6/16 
  Verifying  : 7:device-mapper-event-1.02.158-2.el7_7.2.x86_64                                                  7/16 
  Verifying  : 7:device-mapper-event-libs-1.02.158-2.el7_7.2.x86_64                                             8/16 
  Verifying  : yum-utils-1.1.31-42.el7.noarch                                                                   9/16 
  Verifying  : 7:device-mapper-1.02.140-8.el7.x86_64                                                           10/16 
  Verifying  : 7:device-mapper-event-libs-1.02.140-8.el7.x86_64                                                11/16 
  Verifying  : 7:device-mapper-libs-1.02.140-8.el7.x86_64                                                      12/16 
  Verifying  : 7:lvm2-2.02.171-8.el7.x86_64                                                                    13/16 
  Verifying  : device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64                                          14/16 
  Verifying  : 7:device-mapper-event-1.02.140-8.el7.x86_64                                                     15/16 
  Verifying  : 7:lvm2-libs-2.02.171-8.el7.x86_64                                                               16/16 

Updated:
  device-mapper-persistent-data.x86_64 0:0.8.5-1.el7                 lvm2.x86_64 7:2.02.185-2.el7_7.2                
  yum-utils.noarch 0:1.1.31-52.el7                                  

Dependency Updated:
  device-mapper.x86_64 7:1.02.158-2.el7_7.2                   device-mapper-event.x86_64 7:1.02.158-2.el7_7.2       
  device-mapper-event-libs.x86_64 7:1.02.158-2.el7_7.2        device-mapper-libs.x86_64 7:1.02.158-2.el7_7.2        
  lvm2-libs.x86_64 7:2.02.185-2.el7_7.2                      

Complete!
[root@localhost tmp]# 

使用以下命令来设置稳定的仓库。
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost tmp]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost tmp]# 

安装 Docker Engine-Community
 yum install docker-ce docker-ce-cli containerd.io
如果提示您接受 GPG 密钥,请选是。
[root@localhost tmp]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost tmp]# 
[root@localhost tmp]# 
[root@localhost tmp]#  yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
docker-ce-stable                                                                              | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/primary_db                                                     |  41 kB  00:00:00     
(2/2): docker-ce-stable/x86_64/updateinfo                                                     |   55 B  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.8-3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.8-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.107-3.el7 will be installed
--> Processing Dependency: selinux-policy-targeted >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-3.el7.noarch
--> Processing Dependency: selinux-policy-base >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-3.el7.noarch
--> Processing Dependency: selinux-policy >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-3.el7.noarch
--> Running transaction check
---> Package selinux-policy.noarch 0:3.13.1-166.el7 will be updated
---> Package selinux-policy.noarch 0:3.13.1-252.el7_7.6 will be an update
--> Processing Dependency: policycoreutils >= 2.5-24 for package: selinux-policy-3.13.1-252.el7_7.6.noarch
--> Processing Dependency: libsemanage >= 2.5-13 for package: selinux-policy-3.13.1-252.el7_7.6.noarch
---> Package selinux-policy-targeted.noarch 0:3.13.1-166.el7 will be updated
---> Package selinux-policy-targeted.noarch 0:3.13.1-252.el7_7.6 will be an update
--> Running transaction check
---> Package libsemanage.x86_64 0:2.5-8.el7 will be updated
--> Processing Dependency: libsemanage = 2.5-8.el7 for package: libsemanage-python-2.5-8.el7.x86_64
---> Package libsemanage.x86_64 0:2.5-14.el7 will be an update
--> Processing Dependency: libsepol >= 2.5-10 for package: libsemanage-2.5-14.el7.x86_64
--> Processing Dependency: libselinux >= 2.5-14 for package: libsemanage-2.5-14.el7.x86_64
---> Package policycoreutils.x86_64 0:2.5-17.1.el7 will be updated
--> Processing Dependency: policycoreutils = 2.5-17.1.el7 for package: policycoreutils-python-2.5-17.1.el7.x86_64
---> Package policycoreutils.x86_64 0:2.5-33.el7 will be an update
--> Processing Dependency: libselinux-utils >= 2.5-14 for package: policycoreutils-2.5-33.el7.x86_64
--> Running transaction check
---> Package libselinux.x86_64 0:2.5-11.el7 will be updated
--> Processing Dependency: libselinux(x86-64) = 2.5-11.el7 for package: libselinux-python-2.5-11.el7.x86_64
---> Package libselinux.x86_64 0:2.5-14.1.el7 will be an update
---> Package libselinux-utils.x86_64 0:2.5-11.el7 will be updated
---> Package libselinux-utils.x86_64 0:2.5-14.1.el7 will be an update
---> Package libsemanage-python.x86_64 0:2.5-8.el7 will be updated
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be an update
---> Package libsepol.x86_64 0:2.5-6.el7 will be updated
---> Package libsepol.x86_64 0:2.5-10.el7 will be an update
---> Package policycoreutils-python.x86_64 0:2.5-17.1.el7 will be updated
---> Package policycoreutils-python.x86_64 0:2.5-33.el7 will be an update
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-33.el7.x86_64
--> Running transaction check
---> Package libselinux-python.x86_64 0:2.5-11.el7 will be updated
---> Package libselinux-python.x86_64 0:2.5-14.1.el7 will be an update
---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be updated
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                           Arch             Version                         Repository                  Size
=====================================================================================================================
Installing:
 containerd.io                     x86_64           1.2.13-3.1.el7                  docker-ce-stable            23 M
 docker-ce                         x86_64           3:19.03.8-3.el7                 docker-ce-stable            25 M
 docker-ce-cli                     x86_64           1:19.03.8-3.el7                 docker-ce-stable            40 M
Installing for dependencies:
 container-selinux                 noarch           2:2.107-3.el7                   extras                      39 k
Updating for dependencies:
 libselinux                        x86_64           2.5-14.1.el7                    base                       162 k
 libselinux-python                 x86_64           2.5-14.1.el7                    base                       235 k
 libselinux-utils                  x86_64           2.5-14.1.el7                    base                       151 k
 libsemanage                       x86_64           2.5-14.el7                      base                       151 k
 libsemanage-python                x86_64           2.5-14.el7                      base                       113 k
 libsepol                          x86_64           2.5-10.el7                      base                       297 k
 policycoreutils                   x86_64           2.5-33.el7                      base                       916 k
 policycoreutils-python            x86_64           2.5-33.el7                      base                       457 k
 selinux-policy                    noarch           3.13.1-252.el7_7.6              updates                    492 k
 selinux-policy-targeted           noarch           3.13.1-252.el7_7.6              updates                    7.0 M
 setools-libs                      x86_64           3.3.8-4.el7                     base                       620 k

Transaction Summary
=====================================================================================================================
Install  3 Packages (+ 1 Dependent package)
Upgrade             ( 11 Dependent packages)

Total download size: 98 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
No Presto metadata available for updates
(1/15): container-selinux-2.107-3.el7.noarch.rpm                                              |  39 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.2.13-3.1.el7.x86_64.rpm is not installed
(2/15): containerd.io-1.2.13-3.1.el7.x86_64.rpm                                               |  23 MB  00:00:21     
(3/15): libselinux-utils-2.5-14.1.el7.x86_64.rpm                                              | 151 kB  00:00:01     
(4/15): libselinux-python-2.5-14.1.el7.x86_64.rpm                                             | 235 kB  00:00:01     
(5/15): libsemanage-2.5-14.el7.x86_64.rpm                                                     | 151 kB  00:00:00     
(6/15): libsemanage-python-2.5-14.el7.x86_64.rpm                                              | 113 kB  00:00:00     
(7/15): libsepol-2.5-10.el7.x86_64.rpm                                                        | 297 kB  00:00:00     
(8/15): docker-ce-19.03.8-3.el7.x86_64.rpm                                                    |  25 MB  00:00:24     
(9/15): policycoreutils-2.5-33.el7.x86_64.rpm                                                 | 916 kB  00:00:01     
(10/15): policycoreutils-python-2.5-33.el7.x86_64.rpm                                         | 457 kB  00:00:00     
(11/15): selinux-policy-3.13.1-252.el7_7.6.noarch.rpm                                         | 492 kB  00:00:00     
(12/15): setools-libs-3.3.8-4.el7.x86_64.rpm                                                  | 620 kB  00:00:00     
(13/15): libselinux-2.5-14.1.el7.x86_64.rpm                                                   | 162 kB  00:00:06     
(14/15): selinux-policy-targeted-3.13.1-252.el7_7.6.noarch.rpm                                | 7.0 MB  00:00:12     
(15/15): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                               |  40 MB  00:00:19     
---------------------------------------------------------------------------------------------------------------------
Total                                                                                2.4 MB/s |  98 MB  00:00:40     
Retrieving key from https://download.docker.com/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://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libsepol-2.5-10.el7.x86_64                                                                       1/26 
  Updating   : libselinux-2.5-14.1.el7.x86_64                                                                   2/26 
  Updating   : libsemanage-2.5-14.el7.x86_64                                                                    3/26 
  Updating   : libselinux-utils-2.5-14.1.el7.x86_64                                                             4/26 
  Updating   : policycoreutils-2.5-33.el7.x86_64                                                                5/26 
  Updating   : selinux-policy-3.13.1-252.el7_7.6.noarch                                                         6/26 
  Updating   : selinux-policy-targeted-3.13.1-252.el7_7.6.noarch                                                7/26 
  Updating   : libsemanage-python-2.5-14.el7.x86_64                                                             8/26 
  Updating   : setools-libs-3.3.8-4.el7.x86_64                                                                  9/26 
  Updating   : libselinux-python-2.5-14.1.el7.x86_64                                                           10/26 
  Updating   : policycoreutils-python-2.5-33.el7.x86_64                                                        11/26 
  Installing : 2:container-selinux-2.107-3.el7.noarch                                                          12/26 
  Installing : containerd.io-1.2.13-3.1.el7.x86_64                                                             13/26 
  Installing : 1:docker-ce-cli-19.03.8-3.el7.x86_64                                                            14/26 
  Installing : 3:docker-ce-19.03.8-3.el7.x86_64                                                                15/26 
  Cleanup    : policycoreutils-python-2.5-17.1.el7.x86_64                                                      16/26 
  Cleanup    : selinux-policy-targeted-3.13.1-166.el7.noarch                                                   17/26 
  Cleanup    : selinux-policy-3.13.1-166.el7.noarch                                                            18/26 
  Cleanup    : policycoreutils-2.5-17.1.el7.x86_64                                                             19/26 
  Cleanup    : libselinux-utils-2.5-11.el7.x86_64                                                              20/26 
  Cleanup    : setools-libs-3.3.8-1.1.el7.x86_64                                                               21/26 
  Cleanup    : libselinux-python-2.5-11.el7.x86_64                                                             22/26 
  Cleanup    : libsemanage-python-2.5-8.el7.x86_64                                                             23/26 
  Cleanup    : libsemanage-2.5-8.el7.x86_64                                                                    24/26 
  Cleanup    : libselinux-2.5-11.el7.x86_64                                                                    25/26 
  Cleanup    : libsepol-2.5-6.el7.x86_64                                                                       26/26 
  Verifying  : 2:container-selinux-2.107-3.el7.noarch                                                           1/26 
  Verifying  : selinux-policy-3.13.1-252.el7_7.6.noarch                                                         2/26 
  Verifying  : 1:docker-ce-cli-19.03.8-3.el7.x86_64                                                             3/26 
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                  4/26 
  Verifying  : policycoreutils-python-2.5-33.el7.x86_64                                                         5/26 
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                             6/26 
  Verifying  : libsemanage-2.5-14.el7.x86_64                                                                    7/26 
  Verifying  : libsepol-2.5-10.el7.x86_64                                                                       8/26 
  Verifying  : 3:docker-ce-19.03.8-3.el7.x86_64                                                                 9/26 
  Verifying  : policycoreutils-2.5-33.el7.x86_64                                                               10/26 
  Verifying  : libselinux-python-2.5-14.1.el7.x86_64                                                           11/26 
  Verifying  : libselinux-utils-2.5-14.1.el7.x86_64                                                            12/26 
  Verifying  : selinux-policy-targeted-3.13.1-252.el7_7.6.noarch                                               13/26 
  Verifying  : containerd.io-1.2.13-3.1.el7.x86_64                                                             14/26 
  Verifying  : libselinux-2.5-14.1.el7.x86_64                                                                  15/26 
  Verifying  : libselinux-utils-2.5-11.el7.x86_64                                                              16/26 
  Verifying  : libselinux-2.5-11.el7.x86_64                                                                    17/26 
  Verifying  : libsepol-2.5-6.el7.x86_64                                                                       18/26 
  Verifying  : policycoreutils-python-2.5-17.1.el7.x86_64                                                      19/26 
  Verifying  : selinux-policy-3.13.1-166.el7.noarch                                                            20/26 
  Verifying  : policycoreutils-2.5-17.1.el7.x86_64                                                             21/26 
  Verifying  : libsemanage-python-2.5-8.el7.x86_64                                                             22/26 
  Verifying  : libsemanage-2.5-8.el7.x86_64                                                                    23/26 
  Verifying  : libselinux-python-2.5-11.el7.x86_64                                                             24/26 
  Verifying  : selinux-policy-targeted-3.13.1-166.el7.noarch                                                   25/26 
  Verifying  : setools-libs-3.3.8-1.1.el7.x86_64                                                               26/26 

Installed:
  containerd.io.x86_64 0:1.2.13-3.1.el7   docker-ce.x86_64 3:19.03.8-3.el7   docker-ce-cli.x86_64 1:19.03.8-3.el7  

Dependency Installed:
  container-selinux.noarch 2:2.107-3.el7                                                                             

Dependency Updated:
  libselinux.x86_64 0:2.5-14.1.el7                     libselinux-python.x86_64 0:2.5-14.1.el7                      
  libselinux-utils.x86_64 0:2.5-14.1.el7               libsemanage.x86_64 0:2.5-14.el7                              
  libsemanage-python.x86_64 0:2.5-14.el7               libsepol.x86_64 0:2.5-10.el7                                 
  policycoreutils.x86_64 0:2.5-33.el7                  policycoreutils-python.x86_64 0:2.5-33.el7                   
  selinux-policy.noarch 0:3.13.1-252.el7_7.6           selinux-policy-targeted.noarch 0:3.13.1-252.el7_7.6          
  setools-libs.x86_64 0:3.3.8-4.el7                   

Complete!
[root@localhost tmp]# 

要安装特定版本的 Docker Engine-Community,请在存储库中列出可用版本,然后选择并安装:
列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。
yum list docker-ce --showduplicates | sort -r
[root@localhost tmp]# yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
Installed Packages
 * extras: mirrors.cn99.com

docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.8-3.el7                    @docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable

通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

3.启动 Docker。

systemctl start docker

4.查看docker版本

docker version
[root@localhost ~]#  docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:25:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@localhost ~]# 

5.通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 。

[root@localhost tmp]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@localhost tmp]# 

异常打印
[root@localhost tmp]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
[root@localhost tmp]# 

异常原因:访问国外镜像或者网络问题
解决方案:镜像加速,或者通过docker pull hub.c.163.com/library/hello-world:latest下载镜像后再次执行

6.Docker 镜像加速(设置国内镜像)

[root@localhost tmp]# vim  /etc/docker/daemon.json
在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)
{"registry-mirrors":["https://registry.docker-cn.com"]}
重启docker
[root@localhost tmp]# systemctl daemon-reload
[root@localhost tmp]# systemctl restart docker
检查加速器是否生效
[root@localhost tmp]# docker info

内容中是否有

 Registry Mirrors:
  https://registry.docker-cn.com/

国内加速站点
加速站点对比可参考:https://ieevee.com/tech/2016/09/28/docker-mirror.html#
DOcker国内仓库和镜像:https://www.cnblogs.com/wushuaishuai/p/9984228.html
官方中国版:https://registry.docker-cn.com
网易163:http://hub-mirror.c.163.com
ustc的镜像:https://docker.mirrors.ustc.edu.cn
阿里云:https://3laho3y3.mirror.aliyuncs.com
DaoCloud:http://f1361db2.m.daocloud.io

7.设置docker开机

systemctl enable docker
查看设置是否有效
systemctl list-unit-files | grep docker

迁移镜像存储路径

参考:https://www.cnblogs.com/syxlb/p/9903512.html
posted @ 2020-08-27 11:44  迷茫T亿星  阅读(795)  评论(0编辑  收藏  举报