解决Docker调用yum报错的问题

导读在本篇文章里小编给大家分享的是关于docker容器调用yum报错的解决办法,有兴趣的朋友们可以参考下。

dockerfile里或者在容器里执行yum,报错,找不到源(invalid baseurl xxx),但是宿主机上执行yum是没问题的啊,为什么?

因为不论是dockerfile使用RUN关键字执行yum还是直接进入到容器里面执行yum,它们都是使用的docker镜像里面的源(CentOS是在路径/etc/yum.repo.d/CentOS-Base.repo),所以你要把宿主机上的同路径下的源拷贝到容器里面,然后docker commit一个新的“基础镜像”,这个时候使用docker build xxx(即使用Dockerfile的方式)就不会报错了。

拷贝方法docker cp xxx xxx

dockerfile中执行yum操作报错

我们先看下报错信息:

Sending build context to Docker daemon 9.363 MB
Step 1 : FROM docker.io/centos
---> 196e0ce0c9fb
Step 2 : MAINTAINER liuliangliang
---> Using cache
---> 7d7e06799c20
Step 3 : ADD file/tomcat7.tgz /usr/local/
---> Using cache
---> 10ffdea53a02
Step 4 : RUN yum install java-1.8.0-openjdk -y
---> Running in 7824a339e077
Loaded plugins: fastestmirror, ovl


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= ...

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 
or
subscription-manager repos --disable=

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=.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
The command '/bin/sh -c yum install java-1.8.0-openjdk -y' returned a non-zero code: 1

解决方法

这个你在resolv.conf文件里加上 DNS服务就行了 这个文件在/etc下, 加上

nameserver 8.8.8.8
nameserver 8.8.4.4
search localdomain

就行了

到此这篇关于docker容器调用yum报错的解决办法的文章就介绍到这了。

原文来自:https://www.linuxprobe.com/docker-yum-error.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当我运行"yum install docker-ce"命令时,遇到了一个错误。这个错误可能有多种原因。 首先,可能是因为我的系统没有正确配置Docker的源。在安装Docker之前,我需要添加Docker的官方源到我的系统。我可以通过编辑"/etc/yum.repos.d/docker-ce.repo"文件并添加以下内容来完成这个步骤: ``` [docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg ``` 完成后,我可以再次运行"yum install docker-ce"命令并检查是否仍然报错。 其次,报错可能是因为我的系统缺少某些依赖包。Docker安装过程中可能需要一些额外的软件包才能正常运行。我可以运行以下命令安装这些依赖包: ``` yum install -y yum-utils device-mapper-persistent-data lvm2 ``` 完成后,我再次运行"yum install docker-ce"命令并检查是否仍然出现报错。 最后,报错也可能是由于我之前已经安装了旧版本的Docker而导致的。在安装新版本之前,我需要先将旧版本的Docker卸载掉。我可以运行以下命令来卸载旧版本的Docker: ``` yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine ``` 卸载完成后,我可以再次运行"yum install docker-ce"命令来安装新版本的Docker,并检查是否仍然报错。 综上所述,当我在运行"yum install docker-ce"命令时遇到报错,我可以尝试添加Docker的官方源、安装依赖包或卸载旧版本的Docker解决这个问题
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值