Docker——CentOS7安装Docker环境

CentOs 7 安装 Docker

​ Docker 是一个开源的应用容器引擎,是一个轻量级容器技术,Docker 支持将软件编译成一个镜像,然后在镜像中对各种软件做好配置,将镜像发布出去,使用者们都可以直接使用这个镜像、

​ 运行中的这个镜像被称为容器,容器的启动是非常快速的,下面我们就来介绍如何在 CentOS 7 系统中安装 Docker

准备工作

​ 首先,Docker 官方要求 Linux 内核版本必须在3.8以上,建议3.10以上,我们可以使用uname -a指令来查看内核版本

1
2
[stephen@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

​ 我这里已经是3.10以上的版本了,如果不是的话,我们需要使用sudo yum update指令来更新软件包及内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[stephen@localhost ~]$ sudo yum update

我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:

#1) 尊重别人的隐私。
#2) 输入前要先考虑(后果和风险)。
#3) 权力越大,责任越大。

[sudo] stephen 的密码:
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/4): extras/7/x86_64/primary_db | 165 kB 00:00
(2/4): base/7/x86_64/group_gz | 165 kB 00:00
(3/4): base/7/x86_64/primary_db | 6.0 MB 00:04
(4/4): updates/7/x86_64/primary_db | 7.6 MB 00:07
Determining fastest mirrors
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 GeoIP.x86_64.0.1.5.0-11.el7 将被 升级
---> 软件包 GeoIP.x86_64.0.1.5.0-14.el7 将被 更新
--> 正在处理依赖关系 geoipupdate,它被软件包 GeoIP-1.5.0-14.el7.x86_64 需要
---> 软件包 ModemManager.x86_64.0.1.6.0-2.el7 将被 升级
---> 软件包 ModemManager.x86_64.0.1.6.10-3.el7_6 将被 更新
---> 软件包 ModemManager-glib.x86_64.0.1.6.0-2.el7 将被 升级
......
......
......
zenity.x86_64 0:3.28.1-1.el7
zlib.x86_64 0:1.2.7-18.el7

替代:
caribou.x86_64 0:0.4.21-1.el7
caribou-gtk2-module.x86_64 0:0.4.21-1.el7
caribou-gtk3-module.x86_64 0:0.4.21-1.el7
gnome-dictionary-libs.x86_64 0:3.20.0-1.el7
gnome-tweak-tool.noarch 0:3.22.0-1.el7
grub2.x86_64 1:2.02-0.64.el7.centos
grub2-tools.x86_64 1:2.02-0.64.el7.centos
pyatspi.noarch 0:2.20.3-1.el7
python2-caribou.noarch 0:0.4.21-1.el7
urw-fonts.noarch 0:2.4-16.el7

完毕!

​ 接下来我们就可以安装 Docker 了

安装 Docker

​ 检测过内核版本后,我们就可以使用yum install docker命令安装 Docker,我们需要使用 root 权限来操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[stephen@localhost ~]$ su root
密码:
[root@localhost stephen]# yum install docker
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker.x86_64.2.1.13.1-109.gitcccb291.el7.centos 将被 安装
--> 正在处理依赖关系 docker-common = 2:1.13.1-109.gitcccb291.el7.centos,它被软件包 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 需要
--> 正在处理依赖关系 docker-client = 2:1.13.1-109.gitcccb291.el7.centos,它被软件包 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 需要
--> 正在处理依赖关系 subscription-manager-rhsm-certificates,它被软件包 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 需要
......
......
container-selinux.noarch 2:2.107-3.el7
container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7
containers-common.x86_64 1:0.1.37-3.el7.centos
docker-client.x86_64 2:1.13.1-109.gitcccb291.el7.centos
docker-common.x86_64 2:1.13.1-109.gitcccb291.el7.centos
libyaml.x86_64 0:0.1.4-11.el7_0
oci-register-machine.x86_64 1:0-6.git2b44233.el7
oci-systemd-hook.x86_64 1:0.2.0-1.git05e6923.el7_6
oci-umount.x86_64 2:2.5-3.el7
python-pytoml.noarch 0:0.1.14-1.git7dea353.el7
subscription-manager-rhsm-certificates.x86_64 0:1.24.13-4.el7.centos

完毕!

启动 Docker

​ 上述步骤执行结束并出现完毕!字样,说明我们已经在 CentOS 系统上成功安装了 Docker,我们通过执行systemctl start docker启动 Docker 并使用docker -v查看我们 Docker 的版本

1
2
3
[root@localhost stephen]# systemctl start docker
[root@localhost stephen]# docker -v
Docker version 1.13.1, build cccb291/1.13.1

​ 到这里,我们的 Docker 就已经成功的安装在 CentOS 操作系统中了,但是我们没此重启操作系统都要重启 Docker

设置 Docker 的自启动

​ 通过使用systemctl enable docker可以设置 Docker 的开机自启动

1
2
[root@localhost stephen]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

关闭 Docker

​ 使用systemctl stop docker命令可以关闭 Docker

1
[root@localhost stephen]# systemctl stop docker
-------------本文结束感谢您的阅读-------------