1.检查linux内核版本
uname -r
要求linux内核版本不低于3.10
2.安装gcc相关
yum -y install gcc
yum -y install gcc-c++
3.更新linux内核
若不更新可能会发生版本冲突,此操作需要较长的时间
更新后需重启linux
yum -y update
可能会报的错误:selinux avc
安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是 Linux 的一个安全子系统
SELinux 有三种工作模式,分别为:
- enforcing:强制模式, 执行SELinux规则,违反的行为会被阻止
- permissive:宽容模式,执行SELinux规则,违反的行不会被阻止
- disabled:关闭SELinux
解决方法:
getenforce 0 # 查看selinux目前处于的模式
setenforce 0 # 开启permissive模式,注:重启失效
4.安装需要的软件包
yum install -y yum-utils
5.设置镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
6.更新yum软件包索引
yum makecache fast
7.安装docker
yum -y install docker-ce docker-ce-cli containerd.io
注:可能会报与第3步相同的错误,需要将selinux模式改为permissive,再执行安装操作
8.测试
# 启动docker
systemctl start docker
# 查看docker版本
docker version
# hello world
docker run hello-world
启动报错:
Job for docker.service failed because the control process exited with error code. See “systemctl status docker.service” and “journalctl -xe” for details.
通常是因为没有更新linux内核,发生了版本冲突,执行第3步即可