无法在docker容器中找到包

时间:2016-07-20 12:32:51

标签: git docker ubuntu-14.04 dockerfile

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

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

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

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

RUN apt-get -y update &&\
    apt-get -y upgrade &&\
    apt-get install -y --force-yes git &&\
    apt-get clean

当你运行构建时:

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