今天跟大家分享一下我在centos的linux环境下安装docker的过程。
根据教程(黑马程序员B站的微服务教程Docs)。
首先输入ping baidu.com看看机器是否可以联网。下面一切都是在能联网的基础上
一,
卸载旧的Docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
目前都没有问题。
接下来问题出现了。
二,
接下来要安装一个yum工具(准备工作)
于是我输入了如下代码:
yum install -y yum-utils
运行后就报出错误如下:
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#7 - "Failed to connect to 2a05:d012:8b5:6503:9efb:5cad:348f:e826: Network is unreachable" 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. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ...
4. Disable the repository permanently, 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> or subscription-manager repos --disable=<repoid>
5. 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 find a valid baseurl for repo: base/7/x86_64
于是我询问gpt。
gpt让我 更换镜像源。编辑/etc/yum.repos.d/CentOS-Base.repo文件,将其中的baseurl和mirrorlist更改为其他可用的镜像源地址。
我就输入了:
vi /etc/yum.repos.d/CentOS-Base.repo
进入/etc/yum.repos.d/CentOS-Base.repo。修改镜像源为阿里的。
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清除缓存并更新软件包信息:
yum clean all
yum makecache
可是当我志得意满,又一次输入yum install -y yum-utils。以为问题解决了,却还是报出同样的错误。
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#7 - "Failed to connect to 2a05:d012:8b5:6503:9efb:5cad:348f:e826: Network is unreachable" 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. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ...
4. Disable the repository permanently, 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> or subscription-manager repos --disable=<repoid>
5. 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 find a valid baseurl for repo: base/7/x86_64
我就很纳闷。
然后我就陷入了停滞。一直没有进展。无论试什么办法都还是一样的报错。
转折点在我突然想起看看那个教程视频下面的评论。于是找到了解决的办法。
评论内容如下:这个问题是由yum源导致的,备份一下yum源。使用aliyun重新下载一个yum源。删除yum并更新缓存就好了
备份yum源:mv /etc/yum.repo.d/CentOS-Base.repo /etc/yum.repo.d/CentOS-Base.repo.backup
使用阿里云更新yum源:curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清除yum:yum clean all
更新缓存:yum makecache
我试了试。(备份那一步我失败了,但最后好像也没啥影响)
当我在输入yum install -y yum-utils时,显示
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
docker-ce-stable | 3.5 kB 00:00:00
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
有进展。第二步安装yum算是完成了。
三,
执行命令,配置Docker的yum源:
输入代码:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
可是却得到如下报错:
Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 14] curl#7 - "Failed to connect to 2a03:2880:f127:283:face:b00c:0:25de: Network is unreachable"
我这才想起,配置Docker的yum源也应该用阿里的。
于是我有输入:
[root@192 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
显示:
Loaded plugins: fastestmirror, langpacks
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
终于成功了。
四,
执行命令,安装Docker:
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
安装了大概1分钟,看到Complete!
终于成功了,问题解决。
2483





