最近学习SpringCloud的时候用到了Docker,很多环境工具的安装都是基于docker的,因为自己在安装的时候遇到很多的坑,所以这里做一个详细记录,也便于下次自己不再反复入坑
其实安装Docker的步骤还是比较简单的,但是主要麻烦在前面环境的准备上
首先必须满足是64位操作系统并且是3.10以上版本
安装过程主要分为四步:
1)添加yum 源
yum install epel-release -y
yum clean all
yum list
2)安装Docker
yum install docker-io -y
3)启动Docker
systemctl start docker
(停止docker:systemctl stop docker; 重启docker:systemctl restart docker)
4)检查安装结果
docker info
若是自己的环境没有问题的情况下,以上四步很容易就安装成功了,但是我在安装的时候第一步就遇到了问题,下面是详细的错误信息
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Disable the repository, so yum won't use it by default. Yum will then
just ignore the repository until you permanently enable it again or use
--enablerepo for temporary usage:
yum-config-manager --disable <repoid>
4. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again
为了解决yum源的问题,下面我们分为四个步骤进行解决
1)设置网卡开机自动启动
1、输入命令 cd /etc/sysconfig/network-scripts ,使用命令 ls 查看该目录下的所有文件;找到网卡配置文件,本机是【ifcfg-eno16777736】,然后vim ifcfg-eno16777736,进行修改,将 "ONBOOT" 的值修改为 "yes";
修改完重启系统或者重启网卡,输入命令 "reboot" 或 "service network restart"。
2)设置国内dns服务器
输入命令 vi /etc/resolv.conf
添加 nameserver 114.114.114.114
添加完重启系统或者重启网卡,输入命令 "reboot" 或 "service network restart"
3)修改CentOS-Base.repo中的地址
cd /etc/yum.repos.d
vim CentOS-Base.repo
将所有的 "mirrorlist" 注释掉,将所有的 "baseurl" 取消注释(需要修改四处)
修改完重启 ,输入命令 reboot
4)再次使用yum 源命令,分别依次执行下面四个命令(时间可能会很长,需要耐心等待)
yum clean all
yum makecache
yum update
yum install -y lsof
等执行完上面四个命令之后,再次重新进行docker的安装,这一次便可以安装成功了
后续问题,安装完毕Docker,在启动的时候若是报如下错误:
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
因为默认下载的是Docker的最新版本, 但是内核版本低的话可能不兼容新版本Docker, 所以有可能出现如上错误
这个时候需要
1)将以前下载好的Docker卸载干净, 使用如下命令 yum remove docker-*
2)再次更新该Liunx系统的内核版本,使用如下命令 yum update
3)跟新完毕之后重启系统 reboot
再次进行docker的安装,启动,当看到下图结果输出的时候证明Docker安装启动成功