Docker版本分为CE(社区免费版)和EE(企业版,安全)
Docker 要求 CentOS 系统的内核版本高于 3.10 ,首先验证你的服务器是否支持Docker!
通过 uname -r 命令查看当前的内核版本
[root@iZx4xwfjh1zsdsZ /]# uname -r
3.10.0-514.26.2.el7.x86_64
[root@iZx4xwfjh1zsdsZ /]#
可以看到我的服务器是3.10.0,是支持Docker的。
本教程主要演示安装CE版的步骤:
[root@izx4xwfjh1zsdsz /]# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
Result:
Loaded plugins: fastestmirror
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
[root@iZx4xwfjh1zsdsZ /]#
我这台是新的,所以没有依赖项存在。(为了保障docker的顺利安装还是执行下吧!)
[root@izx4xwfjh1zsdsz /]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Result:
Installed:
device-mapper-persistent-data.x86_64 0:0.7.3-3.el7 lvm2.x86_64 7:2.02.177-4.el7 yum-utils.noarch 0:1.1.31-46.el7_5
Dependency Installed:
device-mapper-event.x86_64 7:1.02.146-4.el7 device-mapper-event-libs.x86_64 7:1.02.146-4.el7 libaio.x86_64 0:0.3.109-13.el7
libxml2-python.x86_64 0:2.9.1-6.el7_2.3 lvm2-libs.x86_64 7:2.02.177-4.el7 python-chardet.noarch 0:2.2.1-1.el7_1
python-kitchen.noarch 0:1.1.1-5.el7
Dependency Updated:
device-mapper.x86_64 7:1.02.146-4.el7 device-mapper-libs.x86_64 7:1.02.146-4.el7
Complete!
[root@iZx4xwfjh1zsdsZ /]#
complete!由于空间的大小,没有完整的截图,这是执行完成的界面!
[root@izx4xwfjh1zsdsz /]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Result:
Loaded plugins: fastestmirror
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@iZx4xwfjh1zsdsZ /]#
以后每个软件都优先从阿里云的软件库中下载,如果阿里云仓库没有,会去docker.hub中下载。(与maven仓库同理)
[root@izx4xwfjh1zsdsz /]# sudo yum makecache fast
Result:
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 3.2 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/x86_64/primary_db | 19 kB 00:00:00
Loading mirror speeds from cached hostfile
Metadata Cache Created
[root@iZx4xwfjh1zsdsZ /]#
[root@izx4xwfjh1zsdsz /]# sudo yum -y install docker-ce
由于需要下载并安装docker,有的机器会有点慢,请耐心等待!
Result:
Installed:
docker-ce.x86_64 3:18.09.0-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 checkpolicy.x86_64 0:2.5-6.el7 container-selinux.noarch 2:2.68-1.el7
containerd.io.x86_64 0:1.2.0-3.el7 docker-ce-cli.x86_64 1:18.09.0-3.el7 libcgroup.x86_64 0:0.41-15.el7
libseccomp.x86_64 0:2.3.1-3.el7 libsemanage-python.x86_64 0:2.5-11.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3
policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-2.el7
Dependency Updated:
audit.x86_64 0:2.8.1-3.el7_5.1 audit-libs.x86_64 0:2.8.1-3.el7_5.1 libselinux.x86_64 0:2.5-12.el7
libselinux-python.x86_64 0:2.5-12.el7 libselinux-utils.x86_64 0:2.5-12.el7 libsemanage.x86_64 0:2.5-11.el7
libsepol.x86_64 0:2.5-8.1.el7 policycoreutils.x86_64 0:2.5-22.el7 selinux-policy.noarch 0:3.13.1-192.el7_5.6
selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.6
Complete!
[root@iZx4xwfjh1zsdsZ /]#
看到complete!下载并安装成功!
[root@iZx4xwfjh1zsdsZ /]# sudo systemctl start docker
[root@iZx4xwfjh1zsdsZ /]#
以上我们已经将Docker安装好了,接下来测试下Docker是否可以顺利启动:
[root@iZx4xwfjh1zsdsZ /]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.0
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
我们可以看到Docker已经启动成功,而且容器与镜像数都为0,是一个全新的docker服务
[root@iZx4xwfjh1zsdsZ /]# sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@iZx4xwfjh1zsdsZ /]#
到此为止,Docker就已经下载并安装完成!
sudo yum remove docker-ce
sudo rm -rf /var/lib/docker