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报错如何解决内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Docker 容器文件系统详细介绍(图文)

    Docker 容器文件系统详细介绍(图文)

    这篇文章主要介绍了Docker 容器文件系统详细介绍(图文)的相关资料,这里对Docker 容器文件系统进行了具体的分析详解,需要的朋友可以参考下
    2016-12-12
  • Docker启动mysql服务的实现步骤

    Docker启动mysql服务的实现步骤

    本文主要介绍了Docker启动mysql服务的实现步骤,文中根据实例编码详细介绍的十分详尽,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • idea使用docker生成镜像(打包镜像,导入镜像,导出镜像)

    idea使用docker生成镜像(打包镜像,导入镜像,导出镜像)

    使用docker镜像,可以快速地部署和运行应用程序,而无需担心环境差异、依赖项问题等,本文主要介绍了idea使用docker生成镜像,具有一定的参考价值,感兴趣的可以了解一下
    2024-02-02
  • 在Docker中安装Oracle数据库超详细步骤

    在Docker中安装Oracle数据库超详细步骤

    oracle作为全球最强大的关系型数据库,应用在各行各业,下面这篇文章主要给大家介绍了关于在Docker中安装Oracle数据库的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2024-01-01
  • docker 搭建部署 YAPI 框架的详细过程

    docker 搭建部署 YAPI 框架的详细过程

    Yapi是一个高效、易用、功能强大的接口文档管理工具,旨在为开发、产品、测试人员提供更优雅的接口管理服务,可以帮助开发者轻松创建、发布、维护 AP,这篇文章主要介绍了docker 搭建部署 YAPI 框架,需要的朋友可以参考下
    2022-08-08
  • docker-compose up -d和docker-compose up --build的区别

    docker-compose up -d和docker-compose up -

    本文主要介绍了docker-compose up -d和docker-compose up --build的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-07-07
  • Dockerfile基础分享

    Dockerfile基础分享

    在Docker中,构建一个自定义镜像共有两种方法,一是通过commit指令构建,二是通过Dockerfile文件构建。今天我们主要来详细探讨下Dockerfile的一些基础。
    2017-01-01
  • 本地文件如何上传至docker容器

    本地文件如何上传至docker容器

    这篇文章主要介绍了本地文件如何上传至docker容器问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-11-11
  • 关于docker中 WSL 配置与修改问题

    关于docker中 WSL 配置与修改问题

    这篇文章主要介绍了docker中 WSL 配置与修改,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-12-12
  • docker compose 服务启动顺序控制的方法

    docker compose 服务启动顺序控制的方法

    这篇文章主要介绍了docker compose 服务启动顺序控制的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-09

最新评论