docker容器调用yum报错的解决办法

 更新时间:2020年03月25日 14:15:46   作者:尚  
在本篇文章里小编给大家分享的是关于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=<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
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报错的解决办法的文章就介绍到这了,更多相关docker容器调用yum报错如何解决内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • dockerfile echo指定文件多行文本的方法实现

    dockerfile echo指定文件多行文本的方法实现

    这篇文章主要介绍了dockerfile echo指定文件多行文本的方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09
  • docker上安装和卸载MySQL数据库详细图文教程

    docker上安装和卸载MySQL数据库详细图文教程

    Docker是一种容器化技术,可以快速方便地部署和管理应用程序,Mysql 是一个开源的关系型数据库管理,系统这篇文章主要给大家介绍了关于docker上安装和卸载MySQL数据库的相关资料,需要的朋友可以参考下
    2024-05-05
  • Docker搭建svn的方法步骤

    Docker搭建svn的方法步骤

    本文主要介绍了Docker搭建svn的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-01-01
  • Docker Compose 搭建简单的Python网络应用程序(步骤详解)

    Docker Compose 搭建简单的Python网络应用程序(步骤详解)

    在这个页面上,你可以建立一个简单的Python网络应用程序,运行在Docker Compose上,这篇文章主要介绍了Docker Compose 搭建简单的Python网络应用程序,需要的朋友可以参考下
    2022-07-07
  • 在docker中执行linux shell命令的操作

    在docker中执行linux shell命令的操作

    这篇文章主要介绍了在docker中执行linux shell命令的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-03-03
  • Docker Desktop启动失败的解决(Docker failed to initialize Docker Desktop is shutting down)

    Docker Desktop启动失败的解决(Docker failed to i

    本文主要介绍了Docker Desktop启动失败的解决(Docker failed to initialize Docker Desktop is shutting down),文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • Dockerfile打包部署详细图文教程

    Dockerfile打包部署详细图文教程

    这篇文章主要介绍了Dockerfile打包部署的相关资料,并详细解释了从创建Dockerfile到启动容器的每一步过程,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2025-03-03
  • 详解Docker下nginx外挂配置和文件

    详解Docker下nginx外挂配置和文件

    这篇文章主要介绍了Docker下nginx外挂配置和文件,启动容器、查看容器和停止容器的方式方法给大家介绍的非常详细,需要的朋友可以参考下
    2022-01-01
  • Docker如何安装Oracle 19c

    Docker如何安装Oracle 19c

    这篇文章主要介绍了Docker如何安装Oracle 19c问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-12-12
  • 使用Distroless提高容器安全

    使用Distroless提高容器安全

    这篇文章主要为大家介绍了使用Distroless提高容器安全,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-11-11

最新评论