无法在 docker 容器中找到包

Unable to locate packages in docker container

在尝试在 docker 容器中构建我的存储库时,我需要安装 git:

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get upgrade
RUN apt-get clean
RUN apt-get install -y git

构建容器 i 运行 以下命令:

sudo docker build .

我尝试安装的每个软件包都出现以下错误:

 E: Unable to locate package git
 The command '/bin/sh -c apt-get install -y git' returned a non-zero code: 100

我找到的所有答案都声称我需要先 运行 apt-get update,我确实这样做了。

编辑:

试图运行一行中的所有命令:

RUN apt-get update && apt-get install -y git

产生了以下错误:

Err http://archive.ubuntu.com trusty InRelease
Err http://archive.ubuntu.com trusty-updates InRelease
Err http://archive.ubuntu.com trusty-security InRelease
Err http://archive.ubuntu.com trusty Release.gpg
Could not resolve 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease  
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package git
The command '/bin/sh -c apt-get update && apt-get install -y git' returned a non-zero code: 100

首先你需要聚合 运行,顺便试试这个:

RUN set -ue \
    ; apt-get -y update \
    ; apt-get install -y --no-install-recommends --no-install-suggests git \
    ; rm -rf /var/lib/apt/lists/* \
;

并且当您 运行 构建时:

docker build -t <name-of-your-image> .

从更新的输出中,您显示 apt-get update 失败,DNS 解析失败。这是一个网络连接问题,您需要先解决这个问题,然后才能构建从网络中提取包的映像。