当前位置: 首页 > article >正文

CentOS安装Docker教程,及报错。

不知是不是在安装虚拟机的时候漏了什么步骤,以下是我安装好Linux后开始安装Docker碰到的错误!以下是GPT的回答,分享一下。

在CentOS 7 上安装 Docker 的步骤。以下是详细的安装教程:

1. 更新系统

确保系统软件包是最新的。运行以下命令来更新你的 CentOS 系统:

sudo yum update -y

2. 安装必要的依赖

Docker 依赖一些软件包,首先需要安装这些包:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

3. 设置 Docker 仓库

安装 Docker 的官方仓库配置工具:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4. 安装 Docker

现在可以通过以下命令安装 Docker:

sudo yum install docker-ce docker-ce-cli containerd.io

5. 启动 Docker 服务

安装完成后,启动并设置 Docker 服务开机自启动:

sudo systemctl start docker
sudo systemctl enable docker

6. 验证 Docker 是否安装成功

运行以下命令来验证 Docker 是否正常工作:

sudo docker version

如果你能看到 Docker 客户端和服务器的版本信息,说明 Docker 安装成功。

7. 测试 Docker(可选)

你可以运行一个简单的容器来确认 Docker 正常运行:

docker run hello-world

完成这些步骤后,Docker 应该已经在你的 CentOS 7 系统上成功安装并能够正常使用了。


不出意外,报错了!

[root@localhost network-scripts]# sudo yum update -y
已加载插件:fastestmirror
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#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 One of the configured repositories failed (未知),
 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

该错误是因为无法解析 mirrorlist.centos.org,这通常是由于网络问题或 DNS 配置问题引起的。你可以按以下步骤排查并解决问题:

1. 检查网络连接

首先,确认你可以访问互联网。你可以使用 ping 命令测试连接:

ping 8.8.8.8

如果没有响应,说明你的服务器可能无法连接到互联网。确保网络配置正确。

2. 检查 DNS 配置

如果可以 ping 通 IP 地址,但无法解析域名,可能是 DNS 服务器设置有问题。
你可以检查 /etc/resolv.conf 文件,确保 DNS 配置正确。

可以尝试手动设置 Google 的公共 DNS 服务器:

sudo vi /etc/resolv.conf

将以下内容添加到文件中:

nameserver 8.8.8.8
nameserver 8.8.4.4

按Esc键输入:wq保存并退出文件,然后再尝试运行 yum update。

3. 手动配置 CentOS 源

如果网络连接正常,但仍然无法连接到 mirrorlist.centos.org,可以尝试手动设置一个可靠的镜像源。

编辑 CentOS 的基础仓库配置文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

找到如下行:

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

将其注释掉,并替换为以下内容(可以选用离你最近的镜像):

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

同样的,还要替换其他仓库配置(如 updates、extras)中的 mirrorlist 行:

baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/

保存并退出,然后运行:

sudo yum clean all
sudo yum update -y

不出意外,报错继续。

Error downloading packages:
  docker-buildx-plugin-0.14.1-1.el7.x86_64: [Errno 256] No more mirrors to try.
  containerd.io-1.6.33-3.1.el7.x86_64: [Errno 256] No more mirrors to try.

出现 [Errno 256] No more mirrors to try 错误,说明你当前所使用的 Docker 安装源中的某些包无法正常下载。可能的原因包括镜像源不可用或网络问题。以下是一些解决方法:

1. 手动更换 Docker 的镜像源

如果 Docker 的默认镜像源出现问题,你可以尝试使用国内的镜像源来替代。国内有一些提供 Docker 安装包的镜像站点,例如阿里云或清华大学开源镜像站。

替换 Docker 仓库为阿里云镜像源

首先,移除现有的 Docker 仓库:

sudo rm -f /etc/yum.repos.d/docker-ce.repo

然后,添加阿里云的 Docker 仓库:

sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
替换 Docker 仓库为清华大学镜像源

也可以使用清华大学的 Docker 镜像源:

sudo yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

2. 清理缓存并重新安装 Docker

如果镜像源更改之后仍然报错,尝试清理缓存并重新安装 Docker:

sudo yum clean all
sudo yum makecache
sudo yum install docker-ce docker-ce-cli containerd.io

OK 问题解决了!


http://www.kler.cn/news/360816.html

相关文章:

  • RK3568平台开发系列讲解(调试篇)debugfs 文件系统
  • C++中static关键字的用法(实现日期类)
  • 【Vulnhub靶场】Kioptrix Level 5
  • 【算法】深入了解 CRC 校验码的计算过程
  • 【计网笔记】应用层
  • 深度学习的高级应用
  • 1791. 找出星型图的中心节点
  • [云] Project Analysis
  • 【Vue3】将 Element Plus 引入 Vue3 项目
  • minio
  • 手机功耗技术点
  • 关于本地项目推送到Gitee时可能报的错误
  • 微软的 Drasi:一种轻量级的事件驱动编程方法
  • Go:error处理机制和函数
  • uniapp项目结构基本了解
  • 【不要离开你的舒适圈】:猛兽才希望你落单,亲人总让你回家,4个维度全面构建舒适圈矩阵
  • 肉桂酰辅酶A还原酶Cinnamoyl-CoA Reductases(CCR)表征及晶体-文献精读70
  • 三部门联合推铁路电子客票,百望云率先完成产品配置,助力财务服务数智化升级
  • 生命科学的前沿挑战与未来机遇
  • 深入了解路由