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://baike.qcidc.com/14896.html

(0)
晴川运维晴川运维
上一篇 2025年10月8日
下一篇 2025年10月8日

相关推荐

  • Linux下安装Docker具体方法

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化,下面为大家分享一下Li…

    Linux系统 2025年6月12日
  • 简单讲解一下SSH的工作原理

    SSH(Secure Shell)是一套协议标准,可以用来实现两台机器之间的安全登录以及安全的数据传送,其保证数据安全的原理是非对称加密,本篇文章简单讲解一下SSH的工作原理。 S…

    Linux系统 2025年10月26日
  • SparkValue类型的常用算子

    Spark RDD常用算子:Value类型 Spark之所以比Hadoop灵活和强大,其中一个原因是Spark内置了许多有用的算子,也就是方法。通过对这些方法的组合,编程人员就可以…

    Linux系统 2025年10月5日
  • Linux下下配置svn的https访问

    Apache Subversion 通常被缩写成 SVN,是一个开放源代码的版本控制系统,Subversion 在 2000 年由 CollabNet Inc 开发,现在发展成为 …

    Linux系统 2025年6月20日
  • 2022 年 5 个新 sudo 功能

    最近的 sudo 版本增加了新的功能,使你能够观察和控制以前隐藏的问题。 当你想授予你的一些用户管理权限,同时控制和检查他们在你的系统上做什么时,你会使用 sudo。然而…

    Linux系统 2025年6月11日
  • Linux下安装并使用NMState网络管理器

    NMState 是一个网络管理器,允许你按照声明式方法配置主机。这意味着你通过一个北向的声明式 API 定义所需的配置状态,这个工具通过南向的提供者provider应用配置。 目前…

    Linux系统 2025年6月16日
  • Linux桌面环境(桌面系统)大比拼[附带优缺点]

    早期的 linux 系统都是不带界面的,只能通过命令来管理,比如运行程序、编辑文档、删除文件等。所以,要想熟练使用 Linux,就必须记忆很多命令。 后来随着 Windows 的普…

    Linux系统 2025年6月24日
  • 快速上手Vue.js

    Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的。相比于Angular.js,Vue.js提供了更加简洁、更易于理解的API,使得我…

    Linux系统 2025年7月9日
  • 详解golang ssh包使用

    在使用gexpect包发现很多问题之外,这里又尝试使用ssh [email protected]的思路进行用户切换。这里记录下具体的使用方法,遇到的ssh: must s…

    Linux系统 2025年6月21日
  • 详解Linux下字符串的操作方法

    本篇文章为大家讲解一下Linux下对字符串的操作方法, 有需要的小伙伴可以参考一下。 字符串截取 定义字符串 $ str=www.baidu.com 匹配字符串截取 # …

    Linux系统 2025年6月15日

发表回复

登录后才能评论