1、Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。
查看你当前的内核版本
[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64
2、yum包更新到最新
[root@localhost ~]# yum update
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
。。。等等各种日志
3、卸载原来的docker
[root@localhost ~]# yum remove docker docker-common docker-selinux docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-common
No Match for argument: docker-selinux
No Match for argument: docker-engine
No Packages marked for removal
4、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.180-10.el7_6.8.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-50.el7.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-50.el7.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package python-chardet.noarch 0:2.2.1-1.el7_1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================================================
Installing:
yum-utils noarch 1.1.31-50.el7 base 121 k
Installing for dependencies:
libxml2-python x86_64 2.9.1-6.el7_2.3 base 247 k
python-chardet noarch 2.2.1-1.el7_1 base 227 k
python-kitchen noarch 1.1.1-5.el7 base 267 k
Transaction Summary
===========================================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 861 k
Installed size: 4.3 M
Downloading packages:
(1/4): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm | 247 kB 00:00:00
(2/4): python-chardet-2.2.1-1.el7_1.noarch.rpm | 227 kB 00:00:00
(3/4): yum-utils-1.1.31-50.el7.noarch.rpm | 121 kB 00:00:00
(4/4): python-kitchen-1.1.1-5.el7.noarch.rpm | 267 kB 00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 849 kB/s | 861 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-chardet-2.2.1-1.el7_1.noarch 1/4
Installing : python-kitchen-1.1.1-5.el7.noarch 2/4
Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64 3/4
Installing : yum-utils-1.1.31-50.el7.noarch 4/4
Verifying : libxml2-python-2.9.1-6.el7_2.3.x86_64 1/4
Verifying : python-kitchen-1.1.1-5.el7.noarch 2/4
Verifying : yum-utils-1.1.31-50.el7.noarch 3/4
Verifying : python-chardet-2.2.1-1.el7_1.noarch 4/4
Installed:
yum-utils.noarch 0:1.1.31-50.el7
Dependency Installed:
libxml2-python.x86_64 0:2.9.1-6.el7_2.3 python-chardet.noarch 0:2.2.1-1.el7_1 python-kitchen.noarch 0:1.1.1-5.el7
Complete!
5、设置yum源
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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
6、可以查看一下所有仓库中所有docker版本,并选择特定版本安装
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
* updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirrors.aliyun.com
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.aliyun.com
Available Packages
7、安装docker
[root@localhost ~]# yum install docker-ce
Loaded plugins: fastestmirror
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:18.09.7-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.7-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-18.09.7-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.7-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.7-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.99-1.el7_6 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.99-1.el7_6.noarch
---> Package containerd.io.x86_64 0:1.2.6-3.3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:18.09.7-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.4-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.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:
docker-ce x86_64 3:18.09.7-3.el7 docker-ce-stable 19 M
Installing for dependencies:
audit-libs-python x86_64 2.8.4-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
container-selinux noarch 2:2.99-1.el7_6 extras 39 k
containerd.io x86_64 1.2.6-3.3.el7 docker-ce-stable 26 M
docker-ce-cli x86_64 1:18.09.7-3.el7 docker-ce-stable 14 M
libcgroup x86_64 0.41-20.el7 base 66 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
policycoreutils-python x86_64 2.5-29.el7_6.1 updates 456 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 (+10 Dependent packages)
Total download size: 60 M
Installed size: 249 M
Is this ok [y/d/N]: y
Downloading packages:
(1/11): audit-libs-python-2.8.4-4.el7.x86_64.rpm | 76 kB 00:00:00
(2/11): container-selinux-2.99-1.el7_6.noarch.rpm | 39 kB 00:00:00
(3/11): checkpolicy-2.5-8.el7.x86_64.rpm | 295 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.09.7-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 155 kB/s | 34 MB 00:02:56 ETA
Public key for docker-ce-18.09.7-3.el7.x86_64.rpm is not installed
(4/11): docker-ce-18.09.7-3.el7.x86_64.rpm | 19 MB 00:02:39
(5/11): libcgroup-0.41-20.el7.x86_64.rpm | 66 kB 00:00:00
(6/11): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
(7/11): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:00
(8/11): policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm | 456 kB 00:00:00
(9/11): libsemanage-python-2.5-14.el7.x86_64.rpm | 113 kB 00:00:03
containerd.io-1.2.6-3.3.el7.x8 FAILED 59% [=============================================- ] 138 B/s | 36 MB 51:54:12 ETA
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
docker-ce-cli-18.09.7-3.el7.x8 FAILED 34% [==========================- ] 0.0 B/s | 21 MB --:--:-- ETA
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.7-3.el7.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.7-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(10/11): containerd.io-1.2.6-3.3.el7.x86_64.rpm | 26 MB 00:00:20
(11/11): docker-ce-cli-18.09.7-3.el7.x86_64.rpm | 14 MB 00:00:15
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 259 kB/s | 60 MB 00:03:57
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) "
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
Installing : libcgroup-0.41-20.el7.x86_64 1/11
Installing : setools-libs-3.3.8-4.el7.x86_64 2/11
Installing : 1:docker-ce-cli-18.09.7-3.el7.x86_64 3/11
Installing : python-IPy-0.75-6.el7.noarch 4/11
Installing : libsemanage-python-2.5-14.el7.x86_64 5/11
Installing : audit-libs-python-2.8.4-4.el7.x86_64 6/11
Installing : checkpolicy-2.5-8.el7.x86_64 7/11
Installing : policycoreutils-python-2.5-29.el7_6.1.x86_64 8/11
Installing : 2:container-selinux-2.99-1.el7_6.noarch 9/11
Installing : containerd.io-1.2.6-3.3.el7.x86_64 10/11
Installing : 3:docker-ce-18.09.7-3.el7.x86_64 11/11
Verifying : libcgroup-0.41-20.el7.x86_64 1/11
Verifying : checkpolicy-2.5-8.el7.x86_64 2/11
Verifying : policycoreutils-python-2.5-29.el7_6.1.x86_64 3/11
Verifying : audit-libs-python-2.8.4-4.el7.x86_64 4/11
Verifying : libsemanage-python-2.5-14.el7.x86_64 5/11
Verifying : python-IPy-0.75-6.el7.noarch 6/11
Verifying : containerd.io-1.2.6-3.3.el7.x86_64 7/11
Verifying : 3:docker-ce-18.09.7-3.el7.x86_64 8/11
Verifying : 1:docker-ce-cli-18.09.7-3.el7.x86_64 9/11
Verifying : setools-libs-3.3.8-4.el7.x86_64 10/11
Verifying : 2:container-selinux-2.99-1.el7_6.noarch 11/11
Installed:
docker-ce.x86_64 3:18.09.7-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.4-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.99-1.el7_6 containerd.io.x86_64 0:1.2.6-3.3.el7 docker-ce-cli.x86_64 1:18.09.7-3.el7
libcgroup.x86_64 0:0.41-20.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-29.el7_6.1 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
Complete!
8、启动docker,并设置为开机启动
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker version
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.8
Git commit: 2d0083d
Built: Thu Jun 27 17:56:06 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 2d0083d
Built: Thu Jun 27 17:26:28 2019
OS/Arch: linux/amd64
Experimental: false