apt-get 在 Dockerfile 中不工作

apt-get not working in Dockerfile

答案:我仍然不知道真正出了什么问题,但是在我重新启动 docker 和 运行 之后(相同 docker文件,一切都一样),它工作正常。

我在 Windows 上使用 Docker,我的 Docker 文件是

FROM ubuntu:15.04

COPY . /src

RUN apt-get update 
RUN apt-get install -y nodejs 
...etc

但是当我尝试构建图像时,我得到了

WARN[0001] SECURITY WARNING: You are building a Docker image from Windows against a Linux Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories

...

Step 3: RUN apt-get -y update
 --> Using cache
 --->ccd4120f98dd
Removing intermediate container 255796bdef29
Step 4: RUN apt-get install -y nodejs
 ---> Running in f6c1d5a54c7a
Reading package lists...
Reading dependency tree...
Reading state information...
E: Unable to locate package nodejs
INFO[0029] The command [/bin/sh -c apt-get install -y nodejs] returned a non-zero code:100

apt-get 可以工作,但是当我尝试将其他 apt-get 安装行放入其中时,它们也不起作用,所以这似乎不是问题。

我不得不把这个作为答案,因为我根本无法在评论中格式化

应该有更多的输出描述出了什么问题。在临时容器中反复尝试 运行 这些步骤:

docker run --rm -it ubuntu:15.04 bash -l
apt-get update
apt-get install -y nodejs

这是否为您提供了有关故障的更多信息?

更新

试试这个并迭代它:

FROM ubuntu:15.04
RUN apt-get update && apt-get install -y nodejs

我试试你的代码

FROM ubuntu:15.04

COPY . /src

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

对我来说一切正常

当我删除 -y 标志时,我遇到了同样的问题

FROM ubuntu:15.04

COPY . /src

RUN apt-get update
RUN apt-get install nodejs

您使用的是正确的 Dockerfile 吗?

确保使用正确的 Dockerfile。如果是,请尝试使用其他图片。

我重新启动 docker 并再次尝试,现在一切正常。

我和 Ubuntu Xenial 有同样的问题,问题是由于我主机上的 dnsmaq 服务器 运行。

解决方案是通过注释 /etc/NetworkManager/NetworkManager.conf 中的 dns=dnsmasq 行来禁用此服务器并重新启动:

sudo service network-manager restart

希望对您有所帮助!

我把两行分开了:

RUN apt-get update
RUN apt-get install -y nodejs

发现问题出在 apt-get udpate

尝试了 Abulla 的建议,apt-get update 工作正常。

删除并重新输入我的 Dockerfile 中的 RUN apt-get update 行,一切正常。