Linux Docker:容器找不到本地回购

Linux Docker:容器找不到本地回购,linux,docker,centos,Linux,Docker,Centos,我正在尝试构建centos映像,然后在没有internet访问的公司网络上运行基本的yum命令。在步骤1中成功获取centos工件后,接下来运行yum update,容器尝试使用加载插件,但这显然不起作用。它无法解析该主机,因为没有web访问权限。因此,我得到了一个错误: Loaded plugins: fastestmirror, ovl Determining fastest mirrors ..."Could not resolve host http://mirrorlist.

我正在尝试构建centos映像,然后在没有internet访问的公司网络上运行基本的yum命令。在步骤1中成功获取centos工件后,接下来运行yum update,容器尝试使用加载插件,但这显然不起作用。它无法解析该主机,因为没有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

因此,它会在yum update时出错。

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

使用yum,您必须删除现有的repo,并在运行yum update之前将其替换为您的repo,类似于:

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定义在同一文件夹中,并且必须声明您的repo


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

如果您共享您迄今为止所尝试的内容,将会有很大帮助。你的Dockerfile是什么样子的?你为什么不干脆在一台连接了internet的机器上创建映像,然后将映像移到那里?@Stefano:更新了Dockerfile。上传图片不是一个选项。如果我做对了,也许这会有帮助:这很有意义,听起来很有希望。给我一天左右的时间,让我重新开始这项工作,并尝试这个解决方案。
FROM path.to.repo/centos
RUN rm -rf /etc/yum.repos.d/*.repo
COPY myprivate.repo /etc/yum.repos.d/
RUN yum update