Dockerfile无法build立

直到几天后Dockerfile工作正常,当我试图再次build立它今天它在terminal给出以下错误。 我尝试了多个docker的基础图像,但仍然给出了相同的错误。 谁能帮我这个? 我不认为我错过了任何东西。 如果我错过了,应该早点给我错误,但为什么呢?

 Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease Temporary failure resolving 'security.ubuntu.com' Err:2 http://archive.ubuntu.com/ubuntu xenial InRelease Temporary failure resolving 'archive.ubuntu.com' Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease Temporary failure resolving 'archive.ubuntu.com' Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease Temporary failure resolving 'archive.ubuntu.com' Reading package lists... W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Temporary failure resolving 'archive.ubuntu.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com' 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 software-properties-common 

我的docker版本是Docker version 17.03.2-ce, build f5ec1e2


这里是我的Dockerfile

 FROM ubuntu:16.04 ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -y && \ apt-get install -y software-properties-common && \ apt-add-repository ppa:webupd8team/java && \ apt-get update -y && \ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \ echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \ apt-get install -y oracle-java8-installer && \ apt-get install -y oracle-java8-unlimited-jce-policy && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ rm -rf /var/cache/oracle-jdk8-installer ENV JAVA_HOME /usr/lib/jvm/java-8-oracle 

看起来你的RUN指令有连接错误。

尝试在Ubuntu容器中执行相同的命令。
docker run -it ubuntu bash

然后在容器内执行你的RUN命令。

在我的机器上,你的脚本确实有效。

我只是改变了我的VM播放器networking设置。 将Network Connectionbridged mode to NAT更改bridged mode to NAT 。 现在它的工作

如果您的主机是Ubuntu VM,则可能是无效的/etc/resolve.conf 。 查看主机Ubuntu VM上的/etc/resolv.conf 。 如果它包含nameserver 127.0.1.1 ,那是错误的。

在主机Ubuntu VM上运行这些命令来修复它:

 sudo vi /etc/NetworkManager/NetworkManager.conf # Comment out the line `dns=dnsmasq` with a `#` # restart the network manager service sudo systemctl restart network-manager cat /etc/resolv.conf 

现在/etc/resolv.conf应该有一个名称服务器的有效值,它将被docker容器复制。

概观
有两个部分给你的问题:
1.修复临时解决消息
2.解决包pipe理问题

暂时的决心
这个问题很可能是:
由于您的Internet服务提供商没有正确地将Internet命名(DNS)转发给其外部DNS服务器,
2.由于networking的变化,同样阻止了这种命名 – 例如,新的路由器/调制解调器,重新configuration一个新的configuration交换机。

我们来看看可能的DNS解决问题。

首先,临时添加一个已知的DNS服务器到您的系统。

 echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null 

然后运行sudo apt update

如果这可以修复您的临时parsing消息,那么请等待24小时,以查看您的ISP是否为您解决了问题(或只是联系您的ISP) – 或者您可以永久性地将DNS服务器添加到您的系统:

 echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null 

8.8.8.8是Google自己的DNS服务器。

资源

另一个您可以使用的DNS服务器示例是OpenDNS – 例如:

 echo "nameserver 208.67.222.222" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null 

包pipe理问题

除了临时解决问题外,还有一些包pipe理问题需要纠正。
打开一个terminal并键入: –

 sudo nano /etc/apt/sources.list 

看看你是否从正确的源代码包下载。

要么

如果您使用代理,请使用-E.例如: –
sudo -E apt-get update

一个简单的方法可能是将nslookup archive.ubuntu.com IP写入/etc/hosts ,然后重新启动docker。

当然,它需要你的/etc/docker/daemon.json使用主机的IP。