【问题标题】:Runing apt update && apt install -y sudo in a container fails在容器中运行 apt update && apt install -y sudo 失败
【发布时间】:2018-10-09 00:06:02
【问题描述】:

我正在尝试在 Ubuntu 16.04 中建立这个容器,其中一个步骤是:RUN apt update && apt install -y sudo

此步骤因Temporary failure to resolve 一些存储库而失败。这是此错误的输出:

Step 2/8 : RUN apt update && apt install -y sudo
 ---> Running in 15215f43b522

WARNING: apt does not have a stable CLI interface yet. Use with caution in scripts.

Err http://security.debian.org jessie/updates InRelease

Err http://deb.debian.org jessie InRelease

Err http://apt.postgresql.org jessie-pgdg InRelease

Err http://security.debian.org jessie/updates Release.gpg
  Temporary failure resolving 'security.debian.org'
Err http://deb.debian.org jessie-updates InRelease

Err http://apt.postgresql.org jessie-pgdg Release.gpg
  Temporary failure resolving 'apt.postgresql.org'
Err http://deb.debian.org jessie Release.gpg
  Temporary failure resolving 'deb.debian.org'
Err http://deb.debian.org jessie-updates Release.gpg
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/jessie/InRelease  

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/InRelease  

W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease  

W: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/jessie-pgdg/InRelease  

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg  Temporary failure resolving 'security.debian.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/jessie-pgdg/Release.gpg  Temporary failure resolving 'apt.postgresql.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Some index files failed to download. They have been ignored, or old ones used instead.
Building dependency tree...
Reading state information...
All packages are up to date.

WARNING: apt does not have a stable CLI interface yet. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package sudo

我能够在我的主机上 ping 存储库。但是上面的输出似乎表明这些主机无法从出现的容器中ping通。

感谢任何帮助。

【问题讨论】:

    标签: linux postgresql docker ubuntu debian


    【解决方案1】:

    似乎DNS 无法解析。您可以尝试以下两种解决方案之一:

    1. 使用--dns=xx.xx.xx.xx 启动容器。

    类似docker run --dns=xx.xx.xx.xx images

    1. 修改主机中的/etc/docker/daemon.json,修改后重启docker守护进程。

    daemon.json 中添加如下内容:

    {
        "dns":[xx.xx.xx.xx]
    }
    

    【讨论】:

      【解决方案2】:

      由于 apt 会随版本改变其行为(参见 man apt 中的描述),在命令行中输入 apt upgrade 将带您进入最新版本,并且很可能会解决连接到存储库的问题.但是,请采取以下步骤以确保您涵盖更多基础:

      1. 将 apt upgrade 添加到您的容器中

      2. 手动安装 sudo (apt-get install sudo)

      3. 修复 Docker 容器命令的最后手段:RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-12
        • 2021-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多