【问题标题】:Docker: container cannot find local repoDocker:容器找不到本地仓库
【发布时间】:2021-02-16 11:31:24
【问题描述】:

我正在尝试构建一个 centos 映像,然后从无法访问 Internet 的公司网络运行基本的 yum 命令。在步骤 1 中成功获取 centos 工件后,接下来是 RUN yum update,容器尝试使用 http://mirrorlist.centos.org 加载插件,这显然行不通。它无法解析该主机,因为没有 Web 访问权限。所以,我得到了错误:

Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
..."Could not resolve host http://mirrorlist.centos.org; Unknown error"

     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
The command '/bin/sh -c yum update' returned a non-zero code: 1

我在 /etc/yum.repos.d 中有一个 repo 文件,其中包含描述 here 的内容。在该文件中,我有多个本地回购 URL。 [updates] 条目有一个用于 /updates 的 baseurl。当我在 Dockerfile 中执行 RUN yum update 时,容器是否应该使用此条目?容器如何知道在哪里寻找本地镜像仓库或其他仓库?

主机上的 localhost 与容器中的 localhost 是否也存在问题?

我研究了十几个 S.O.没有运气的条目。

更新:Dockerfile 到目前为止...

FROM path.to.repo/centos
RUN yum update

所以,yum 更新时会出错。

【问题讨论】:

  • 如果您分享您到目前为止所尝试的内容,将会有很大帮助。你的 Dockerfile 是什么样子的?
  • 为什么不简单地在有互联网连接的机器上构建图像,然后将图像移动到那里?
  • @Stefano:使用 Dockerfile 更新。上传图片不是一种选择。
  • 如果我做对了,也许这会有所帮助:hub.docker.com/r/intraway/yum-repo#docker-image

标签: linux docker centos


【解决方案1】:

当您创建无法访问网络而只能访问内部网络的图像时,您必须在尝试使用它们之前更改工具配置。

使用 yum,您必须删除现有的 repos 并在 RUN yum update 之前用您的 repos 替换它们,类似这样:

FROM path.to.repo/centos
RUN rm -rf /etc/yum.repos.d/*.repo
COPY myprivate.repo /etc/yum.repos.d/
RUN yum update

文件 myprivate.repo 必须与您的 Dockerfile 定义在同一文件夹中,并且必须声明您的 repos。

此外,这个创建的图像现在可以用作您需要创建的所有其他图像的基础图像。

【讨论】:

  • 这很有意义,听起来很有希望。给我一天左右的时间让我重新开始努力并尝试这个解决方案。
猜你喜欢
  • 2021-07-28
  • 2012-10-22
  • 2021-05-22
  • 2017-01-19
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多