文章目录


一、安装简介


Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。CentOS 7 的内核一般都是3.10的,而CentOS 6.X 的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到3.10版本。


二、在CentOS 7上安装Docker常用命令

1、卸载掉旧版本的 Docker:
yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

2、执行以下安装命令去安装依赖包:
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

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

# 若执行报错,则配置yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo


或一键安装Docker:
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh


systemctl start docker
systemctl status docker


3、检查版本
docker version
docker info

三、执行过程:

1、卸载旧版本

[root@lhrdocker ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@lhrdocker ~]# docker ps
bash: docker: command not found...
[root@lhrdocker ~]# yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
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-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal

2、安装依赖包

[root@lhrdocker ~]# yum install -y yum-utils device-mapper-persistent-data lvvm2
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/7): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/7): epel/x86_64/group_gz | 95 kB 00:00:00
(3/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(4/7): extras/7/x86_64/primary_db | 194 kB 00:00:01
(5/7): epel/x86_64/primary_db | 6.8 MB 00:00:01
(6/7): updates/7/x86_64/primary_db | 2.9 MB 00:00:02
(7/7): base/7/x86_64/primary_db | 6.1 MB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.6.3-1.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.8.5-2.el7 will be an update
---> Package lvm2.x86_64 7:2.02.166-1.el7 will be updated
---> Package lvm2.x86_64 7:2.02.186-7.el7_8.2 will be an update
--> Processing Dependency: lvm2-libs = 7:2.02.186-7.el7_8.2 for package: 7:lvm2-2.02.186-7.el7_8.2.x86_64
--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_141)(64bit) for package: 7:lvm2-2.02.186-7.el7_8.2.x86_64
--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_138)(64bit) for package: 7:lvm2-2.02.186-7.el7_8.2.x86_64
---> Package yum-utils.noarch 0:1.1.31-40.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Running transaction check
---> Package device-mapper-libs.x86_64 7:1.02.135-1.el7 will be updated
--> Processing Dependency: device-mapper-libs = 7:1.02.135-1.el7 for package: 7:device-mapper-1.02.135-1.el7.x86_64
---> Package device-mapper-libs.x86_64 7:1.02.164-7.el7_8.2 will be an update
---> Package lvm2-libs.x86_64 7:2.02.166-1.el7 will be updated
--> Processing Dependency: lvm2-libs = 7:2.02.166-1.el7 for package: 7:lvm2-python-libs-2.02.166-1.el7.x86_64
---> Package lvm2-libs.x86_64 7:2.02.186-7.el7_8.2 will be an update
--> Processing Dependency: device-mapper-event = 7:1.02.164-7.el7_8.2 for package: 7:lvm2-libs-2.02.186-7.el7_8.2.x86_64
--> Running transaction check
---> Package device-mapper.x86_64 7:1.02.135-1.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.164-7.el7_8.2 will be an update
---> Package device-mapper-event.x86_64 7:1.02.135-1.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.164-7.el7_8.2 will be an update
--> Processing Dependency: device-mapper-event-libs = 7:1.02.164-7.el7_8.2 for package: 7:device-mapper-event-1.02.164-7.el7_8.2.x86_64
---> Package lvm2-python-libs.x86_64 7:2.02.166-1.el7 will be updated
---> Package lvm2-python-libs.x86_64 7:2.02.186-7.el7_8.2 will be an update
--> Running transaction check
---> Package device-mapper-event-libs.x86_64 7:1.02.135-1.el7 will be updated
---> Package device-mapper-event-libs.x86_64 7:1.02.164-7.el7_8.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-2.el7 base 422 k
lvm2 x86_64 7:2.02.186-7.el7_8.2 updates 1.3 M
yum-utils noarch 1.1.31-54.el7_8 updates 122 k
Updating for dependencies:
device-mapper x86_64 7:1.02.164-7.el7_8.2 updates 295 k
device-mapper-event x86_64 7:1.02.164-7.el7_8.2 updates 191 k
device-mapper-event-libs x86_64 7:1.02.164-7.el7_8.2 updates 190 k
device-mapper-libs x86_64 7:1.02.164-7.el7_8.2 updates 324 k
lvm2-libs x86_64 7:2.02.186-7.el7_8.2 updates 1.1 M
lvm2-python-libs x86_64 7:2.02.186-7.el7_8.2 updates 188 k

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

Total download size: 4.1 M
Downloading packages:
No Presto metadata available for base
No Presto metadata available for updates
(1/9): device-mapper-1.02.164-7.el7_8.2.x86_64.rpm | 295 kB 00:00:00
(2/9): device-mapper-event-libs-1.02.164-7.el7_8.2.x86_64.rpm | 190 kB 00:00:00
(3/9): device-mapper-event-1.02.164-7.el7_8.2.x86_64.rpm | 191 kB 00:00:00
(4/9): device-mapper-libs-1.02.164-7.el7_8.2.x86_64.rpm | 324 kB 00:00:00
(5/9): lvm2-libs-2.02.186-7.el7_8.2.x86_64.rpm | 1.1 MB 00:00:00
(6/9): lvm2-2.02.186-7.el7_8.2.x86_64.rpm | 1.3 MB 00:00:00
(7/9): device-mapper-persistent-data-0.8.5-2.el7.x86_64.rpm | 422 kB 00:00:00
(8/9): yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00
(9/9): lvm2-python-libs-2.02.186-7.el7_8.2.x86_64.rpm | 188 kB 00:00:00
------------------------------------------------------------------------------------------------------------------------
Total 4.2 MB/s | 4.1 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch
Updating : 7:device-mapper-1.02.164-7.el7_8.2.x86_64 1/18
Updating : 7:device-mapper-libs-1.02.164-7.el7_8.2.x86_64 2/18
Updating : 7:device-mapper-event-libs-1.02.164-7.el7_8.2.x86_64 3/18
Updating : 7:device-mapper-event-1.02.164-7.el7_8.2.x86_64 4/18
Updating : 7:lvm2-libs-2.02.186-7.el7_8.2.x86_64 5/18
Updating : device-mapper-persistent-data-0.8.5-2.el7.x86_64 6/18
Updating : 7:lvm2-2.02.186-7.el7_8.2.x86_64 7/18
Updating : 7:lvm2-python-libs-2.02.186-7.el7_8.2.x86_64 8/18
Updating : yum-utils-1.1.31-54.el7_8.noarch 9/18
Cleanup : 7:lvm2-2.02.166-1.el7.x86_64 10/18
Cleanup : 7:lvm2-python-libs-2.02.166-1.el7.x86_64 11/18
Cleanup : yum-utils-1.1.31-40.el7.noarch 12/18
Cleanup : 7:lvm2-libs-2.02.166-1.el7.x86_64 13/18
Cleanup : 7:device-mapper-event-1.02.135-1.el7.x86_64 14/18
Cleanup : 7:device-mapper-event-libs-1.02.135-1.el7.x86_64 15/18
Cleanup : 7:device-mapper-1.02.135-1.el7.x86_64 16/18
Cleanup : 7:device-mapper-libs-1.02.135-1.el7.x86_64 17/18
Cleanup : device-mapper-persistent-data-0.6.3-1.el7.x86_64 18/18
Verifying : 7:device-mapper-event-1.02.164-7.el7_8.2.x86_64 1/18
Verifying : device-mapper-persistent-data-0.8.5-2.el7.x86_64 2/18
Verifying : 7:lvm2-libs-2.02.186-7.el7_8.2.x86_64 3/18
Verifying : 7:lvm2-2.02.186-7.el7_8.2.x86_64 4/18
Verifying : 7:device-mapper-libs-1.02.164-7.el7_8.2.x86_64 5/18
Verifying : 7:lvm2-python-libs-2.02.186-7.el7_8.2.x86_64 6/18
Verifying : yum-utils-1.1.31-54.el7_8.noarch 7/18
Verifying : 7:device-mapper-1.02.164-7.el7_8.2.x86_64 8/18
Verifying : 7:device-mapper-event-libs-1.02.164-7.el7_8.2.x86_64 9/18
Verifying : 7:device-mapper-event-1.02.135-1.el7.x86_64 10/18
Verifying : 7:device-mapper-event-libs-1.02.135-1.el7.x86_64 11/18
Verifying : 7:lvm2-2.02.166-1.el7.x86_64 12/18
Verifying : yum-utils-1.1.31-40.el7.noarch 13/18
Verifying : device-mapper-persistent-data-0.6.3-1.el7.x86_64 14/18
Verifying : 7:lvm2-python-libs-2.02.166-1.el7.x86_64 15/18
Verifying : 7:device-mapper-libs-1.02.135-1.el7.x86_64 16/18
Verifying : 7:device-mapper-1.02.135-1.el7.x86_64 17/18
Verifying : 7:lvm2-libs-2.02.166-1.el7.x86_64 18/18

Updated:
device-mapper-persistent-data.x86_64 0:0.8.5-2.el7 lvm2.x86_64 7:2.02.186-7.el7_8.2
yum-utils.noarch 0:1.1.31-54.el7_8

Dependency Updated:
device-mapper.x86_64 7:1.02.164-7.el7_8.2 device-mapper-event.x86_64 7:1.02.164-7.el7_8.2
device-mapper-event-libs.x86_64 7:1.02.164-7.el7_8.2 device-mapper-libs.x86_64 7:1.02.164-7.el7_8.2
lvm2-libs.x86_64 7:2.02.186-7.el7_8.2 lvm2-python-libs.x86_64 7:2.02.186-7.el7_8.2

Complete!

3、安装Docker

[root@lhrdocker yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reepo
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
[root@lhrdocker yum.repos.d]# yum -y 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 | 45 kB 00:00:00
(2/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.2.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.12-3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.12-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.1-1.c57a6f9.el7 will be installed
--> Processing Dependency: selinux-policy-targeted >= 3.13.1-216.el7 for package: 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch
--> Processing Dependency: selinux-policy-base >= 3.13.1-216.el7 for package: 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch
--> Processing Dependency: selinux-policy >= 3.13.1-216.el7 for package: 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch
--> Processing Dependency: policycoreutils >= 2.5-11 for package: 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch
--> Running transaction check
---> Package policycoreutils.x86_64 0:2.5-8.el7 will be updated
--> Processing Dependency: policycoreutils = 2.5-8.el7 for package: policycoreutils-python-2.5-8.el7.x86_64
---> Package policycoreutils.x86_64 0:2.5-34.el7 will be an update
--> Processing Dependency: libsepol >= 2.5-10 for package: policycoreutils-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage >= 2.5-14 for package: policycoreutils-2.5-34.el7.x86_64
--> Processing Dependency: libselinux-utils >= 2.5-14 for package: policycoreutils-2.5-34.el7.x86_64
---> Package selinux-policy.noarch 0:3.13.1-102.el7 will be updated
---> Package selinux-policy.noarch 0:3.13.1-266.el7 will be an update
---> Package selinux-policy-targeted.noarch 0:3.13.1-102.el7 will be updated
---> Package selinux-policy-targeted.noarch 0:3.13.1-266.el7 will be an update
--> Running transaction check
---> Package libselinux-utils.x86_64 0:2.5-6.el7 will be updated
---> Package libselinux-utils.x86_64 0:2.5-15.el7 will be an update
--> Processing Dependency: libselinux(x86-64) = 2.5-15.el7 for package: libselinux-utils-2.5-15.el7.x86_64
---> Package libsemanage.x86_64 0:2.5-4.el7 will be updated
--> Processing Dependency: libsemanage = 2.5-4.el7 for package: libsemanage-python-2.5-4.el7.x86_64
---> Package libsemanage.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-8.el7 will be updated
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be an update
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Running transaction check
---> Package libselinux.x86_64 0:2.5-6.el7 will be updated
--> Processing Dependency: libselinux(x86-64) = 2.5-6.el7 for package: libselinux-python-2.5-6.el7.x86_64
---> Package libselinux.x86_64 0:2.5-15.el7 will be an update
---> Package libsemanage-python.x86_64 0:2.5-4.el7 will be updated
---> Package libsemanage-python.x86_64 0:2.5-14.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
--> Running transaction check
---> Package libselinux-python.x86_64 0:2.5-6.el7 will be updated
---> Package libselinux-python.x86_64 0:2.5-15.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
containerd.io x86_64 1.2.13-3.2.el7 docker-ce-stable 25 M
docker-ce x86_64 3:19.03.12-3.el7 docker-ce-stable 24 M
docker-ce-cli x86_64 1:19.03.12-3.el7 docker-ce-stable 38 M
Installing for dependencies:
container-selinux noarch 2:2.119.1-1.c57a6f9.el7 extras 40 k
Updating for dependencies:
libselinux x86_64 2.5-15.el7 base 162 k
libselinux-python x86_64 2.5-15.el7 base 236 k
libselinux-utils x86_64 2.5-15.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-34.el7 base 917 k
policycoreutils-python x86_64 2.5-34.el7 base 457 k
selinux-policy noarch 3.13.1-266.el7 base 497 k
selinux-policy-targeted noarch 3.13.1-266.el7 base 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
Downloading packages:
No Presto metadata available for base
(1/15): container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm | 40 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-19.03.12-3.el7.x86_64.rpm is not installed
(2/15): docker-ce-19.03.12-3.el7.x86_64.rpm | 24 MB 00:00:23
(3/15): libselinux-python-2.5-15.el7.x86_64.rpm | 236 kB 00:00:00
(4/15): libselinux-2.5-15.el7.x86_64.rpm | 162 kB 00:00:00
(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): libselinux-utils-2.5-15.el7.x86_64.rpm | 151 kB 00:00:00
(8/15): libsepol-2.5-10.el7.x86_64.rpm | 297 kB 00:00:00
(9/15): policycoreutils-2.5-34.el7.x86_64.rpm | 917 kB 00:00:00
selinux-policy-targeted-3.13.1 FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/selinux-policy-targeted-3.13.1-266.el7.noarch.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
Trying other mirror.
(10/15): policycoreutils-python-2.5-34.el7.x86_64.rpm | 457 kB 00:00:00
(11/15): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:00
(12/15): selinux-policy-3.13.1-266.el7.noarch.rpm | 497 kB 00:00:01
(13/15): selinux-policy-targeted-3.13.1-266.el7.noarch.rpm | 7.0 MB 00:00:05
(14/15): containerd.io-1.2.13-3.2.el7.x86_64.rpm | 25 MB 00:00:36
(15/15): docker-ce-cli-19.03.12-3.el7.x86_64.rpm | 38 MB 00:00:20
------------------------------------------------------------------------------------------------------------------------
Total 2.3 MB/s | 98 MB 00:00:43
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
Updating : libsepol-2.5-10.el7.x86_64 1/26
Updating : libselinux-2.5-15.el7.x86_64 2/26
Updating : libsemanage-2.5-14.el7.x86_64 3/26
Updating : libselinux-utils-2.5-15.el7.x86_64 4/26
Updating : policycoreutils-2.5-34.el7.x86_64 5/26
Updating : selinux-policy-3.13.1-266.el7.noarch 6/26
Updating : selinux-policy-targeted-3.13.1-266.el7.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-15.el7.x86_64 10/26
Updating : policycoreutils-python-2.5-34.el7.x86_64 11/26
Installing : 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch 12/26
setsebool: SELinux is disabled.
Installing : containerd.io-1.2.13-3.2.el7.x86_64 13/26
Installing : 1:docker-ce-cli-19.03.12-3.el7.x86_64 14/26
Installing : 3:docker-ce-19.03.12-3.el7.x86_64 15/26
Cleanup : policycoreutils-python-2.5-8.el7.x86_64 16/26
Cleanup : selinux-policy-targeted-3.13.1-102.el7.noarch 17/26
Cleanup : selinux-policy-3.13.1-102.el7.noarch 18/26
Cleanup : policycoreutils-2.5-8.el7.x86_64 19/26
Cleanup : libselinux-utils-2.5-6.el7.x86_64 20/26
Cleanup : setools-libs-3.3.8-1.1.el7.x86_64 21/26
Cleanup : libselinux-python-2.5-6.el7.x86_64 22/26
Cleanup : libsemanage-python-2.5-4.el7.x86_64 23/26
Cleanup : libsemanage-2.5-4.el7.x86_64 24/26
Cleanup : libselinux-2.5-6.el7.x86_64 25/26
Cleanup : libsepol-2.5-6.el7.x86_64 26/26
Verifying : 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch 1/26
Verifying : 1:docker-ce-cli-19.03.12-3.el7.x86_64 2/26
Verifying : libselinux-2.5-15.el7.x86_64 3/26
Verifying : policycoreutils-2.5-34.el7.x86_64 4/26
Verifying : libselinux-utils-2.5-15.el7.x86_64 5/26
Verifying : policycoreutils-python-2.5-34.el7.x86_64 6/26
Verifying : 3:docker-ce-19.03.12-3.el7.x86_64 7/26
Verifying : setools-libs-3.3.8-4.el7.x86_64 8/26
Verifying : selinux-policy-3.13.1-266.el7.noarch 9/26
Verifying : containerd.io-1.2.13-3.2.el7.x86_64 10/26
Verifying : libsemanage-python-2.5-14.el7.x86_64 11/26
Verifying : libsemanage-2.5-14.el7.x86_64 12/26
Verifying : libselinux-python-2.5-15.el7.x86_64 13/26
Verifying : libsepol-2.5-10.el7.x86_64 14/26
Verifying : selinux-policy-targeted-3.13.1-266.el7.noarch 15/26
Verifying : policycoreutils-2.5-8.el7.x86_64 16/26
Verifying : libsepol-2.5-6.el7.x86_64 17/26
Verifying : libselinux-python-2.5-6.el7.x86_64 18/26
Verifying : libselinux-utils-2.5-6.el7.x86_64 19/26
Verifying : libsemanage-python-2.5-4.el7.x86_64 20/26
Verifying : policycoreutils-python-2.5-8.el7.x86_64 21/26
Verifying : selinux-policy-3.13.1-102.el7.noarch 22/26
Verifying : libselinux-2.5-6.el7.x86_64 23/26
Verifying : selinux-policy-targeted-3.13.1-102.el7.noarch 24/26
Verifying : libsemanage-2.5-4.el7.x86_64 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.2.el7 docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-cli.x86_64 1:19.03.12-3.el7

Dependency Installed:
container-selinux.noarch 2:2.119.1-1.c57a6f9.el7

Dependency Updated:
libselinux.x86_64 0:2.5-15.el7 libselinux-python.x86_64 0:2.5-15.el7
libselinux-utils.x86_64 0:2.5-15.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-34.el7 policycoreutils-python.x86_64 0:2.5-34.el7
selinux-policy.noarch 0:3.13.1-266.el7 selinux-policy-targeted.noarch 0:3.13.1-266.el7
setools-libs.x86_64 0:3.3.8-4.el7

Complete!

[root@lhrdocker yum.repos.d]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@lhrdocker yum.repos.d]# systemctl start docker
systemctl status dockcker[root@lhrdocker yum.repos.d]# systemctl status docker

● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-06-24 12:47:51 CST; 2s ago
Docs: https://docs.docker.com
Main PID: 9438 (dockerd)
Memory: 38.3M
CGroup: /system.slice/docker.service
└─9438 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.751029389+08:00" level=info msg="ccResolverWr...=grpc
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.751035457+08:00" level=info msg="ClientConn s...=grpc
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.784895620+08:00" level=info msg="Loading cont...art."
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.874834656+08:00" level=info msg="Default brid...ress"
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.962577618+08:00" level=info msg="Loading cont...one."
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.983199649+08:00" level=warning msg="Not using...rlay2
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.983362127+08:00" level=info msg="Docker daemo...03.12
Jun 24 12:47:50 lhrdocker dockerd[9438]: time="2020-06-24T12:47:50.983421645+08:00" level=info msg="Daemon has c...tion"
Jun 24 12:47:51 lhrdocker dockerd[9438]: time="2020-06-24T12:47:51.066011655+08:00" level=info msg="API listen o...sock"
Jun 24 12:47:51 lhrdocker systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

[root@lhrdocker yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@lhrdocker yum.repos.d]#

[root@lhrdocker yum.repos.d]# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:28 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@lhrdocker yum.repos.d]# docker info
Client:
Debug Mode: false

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.695GiB
Name: lhrdocker
ID: YBFL:WNPR:Y2XV:RPJQ:JYGA:XOXN:YXJL:EO2J:UFFO:JVBW:AZHF:TYME
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

四、一键安装Docker

我们也可以一键安装Docker,如下:

[root@lhrdocker ~]# docker ps
bash: docker: command not found...
[root@lhrdocker ~]# curl -fsSL get.docker.com -o get-docker.sh
[root@lhrdocker ~]# ll
total 56
-rw-------. 1 root root 2152 Sep 13 2018 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Desktop
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Documents
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Downloads
-rw-r--r-- 1 root root 13857 Jun 24 12:57 get-docker.sh
-rw-r--r--. 1 root root 2256 Sep 13 2018 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Music
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Pictures
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Public
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Templates
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Videos

[root@lhrdocker ~]# sh get-docker.sh
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
+ sh -c 'yum install -y -q yum-utils'
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/f09552edffa70f49f553e411c2282fbccfffbeafa21e81e32622b103038b8bae-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
No Presto metadata available for updates
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch
+ sh -c '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
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/9): epel/x86_64/prestodelta | 2.0 kB 00:00:00
(2/9): base/7/x86_64/other_db | 2.6 MB 00:00:00
(3/9): extras/7/x86_64/filelists_db | 205 kB 00:00:00
(4/9): extras/7/x86_64/other_db | 122 kB 00:00:00
(5/9): updates/7/x86_64/other_db | 238 kB 00:00:00
(6/9): updates/7/x86_64/filelists_db | 1.6 MB 00:00:02
(7/9): epel/x86_64/other_db | 3.3 MB 00:00:05
(8/9): base/7/x86_64/filelists_db | 7.1 MB 00:00:06
(9/9): epel/x86_64/filelists_db | 12 MB 00:00:07
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Metadata Cache Created
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-19.03.12-3.el7.x86_64.rpm is not installed
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
setsebool: SELinux is disabled.
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
[root@lhrdocker ~]# If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
[root@lhrdocker ~]# d
[root@lhrdocker ~]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@lhrdocker ~]# systemctl start docker
systemctl status docker[root@lhrdocker ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-06-24 13:12:56 CST; 1s ago
Docs: https://docs.docker.com
Main PID: 9348 (dockerd)
Memory: 38.4M
CGroup: /system.slice/docker.service
└─9348 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.403432651+08:00" level=info msg="ccResolverWrappe...e=grpc
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.403438749+08:00" level=info msg="ClientConn switc...e=grpc
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.422565741+08:00" level=info msg="Loading containe...tart."
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.498364397+08:00" level=info msg="Default bridge (...dress"
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.586263842+08:00" level=info msg="Loading containe...done."
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614176483+08:00" level=warning msg="Not using nat...erlay2
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614312232+08:00" level=info msg="Docker daemon" c....03.12
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614366802+08:00" level=info msg="Daemon has compl...ation"
Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.700953028+08:00" level=info msg="API listen on /v....sock"
Jun 24 13:12:56 lhrdocker systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@lhrdocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@lhrdocker ~]#