docker容器中---------------yum 安装出现的报错错误操作记录

1. docker容器中 yum 安装出现的报错

Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os error was
12: Timeout on http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os: (28, ‘Connection timed out after 30215 milliseconds’)

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 find a valid baseurl for repo: base/7/x86_64

解决方法:
先检查下 ping 网络,看看是不是网络问题
1.可能是网络出现问题
vim etc/sysconfig/network-scripts/ifcfg-ens33
修改配置ONBOOT=no改为ONBOOT=yes
wq保存退出
service network restart重启网络服务

2.修改下DNS 配置
vim /etc/resolv.conf
nameserver 改成 8.8.8.8或者自己虚拟机的IP

2. CentOS7 docker run 以后 出现网络问题WARNING: IPv4 forwarding is disabled. Networking will not work.

解决方法:
添加路由转发功能
vi /etc/sysctl.conf
添加net.ipv4.ip_forward=1
重启网络服务以及docker服务systemctl restart network
重新docker run

3.Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Job for docker.service failed because start of the service was attempted too often

docker version

在这里插入图片描述
解决方式

cd /etc/docker
ls
没有 daemon.json 就手动添加
把daemon.json改为daemon.conf。使用mv命令修改后,docker启动正常。这个方式是不正确的

设置/etc/docker/daemon.json 文件,将其中关于registry的配置删除后重启docker就好。

### Docker 安装失败问题分析 当遇到 `Docker installation failed` 的错误提示时,通常是因为某些依赖项未满足或配置不正确。以下是可能的原因以及解决方案: #### 1. **缺少必要的组件** 如果系统中缺失了 `docker-runc` 或其他必要组件,则可能会导致安装失败。可以通过以下命令检查并安装所需的包: ```bash yum install -y containerd.io docker-ce-cli docker-ce ``` 此操作会确保所有必需的软件包被正确安装[^1]。 #### 2. **YUM 软件冲突** 有时 YUM 软件中的旧版或不稳定版本可能导致安装失败。可以尝试清理缓存并重新加载仓库元数据: ```bash yum clean all && yum makecache fast ``` 对于特定版本的安装需求,可忽略过期警告并通过强制参数完成安装: ```bash yum install --setopt=obsoletes=0 docker-ce-<version> ``` 其中 `<version>` 是目标版本号[^4]。 #### 3. **SELinux 干扰** 在启用了 SELinux 的环境中,可能存在权限限制问题。可通过临时禁用 SELinux 来验证其影响: ```bash setenforce 0 ``` 永久修改需编辑 `/etc/selinux/config` 文件并将 `SELINUX=enforcing` 改为 `SELINUX=permissive` 后重启系统[^5]。 #### 4. **网络代理设置不当** 部分情况下由于国内镜像站点访问受限,建议更换为阿里云或其他稳定镜像地址: ```bash wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo ``` #### 5. **防火墙阻止端口通信** 确认是否有防火墙规则阻碍了容器间的正常通讯。关闭 firewalld 可作为初步测试手段: ```bash systemctl stop firewalld systemctl disable firewalld ``` --- ### 示例脚本修复流程 综合上述方法编写自动化修复脚本如下所示: ```bash #!/bin/bash # 更新系统基础库文件 yum update -y # 添加官方推荐存储库链接至本地目录下 curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh # 替换默认远程资位置为中国区加速节点 mv /etc/yum.repos.d/docker*.repo ~/backup/ cat <<EOF >/etc/yum.repos.d/docker-ce.repo [docker-ce-stable] name=Docker CE Stable - \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg EOF # 开始正式部署过程 yum install -y docker-ce docker-ce-cli containerd.io systemctl enable --now docker ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值