[英]Dockerfile fails to build
直到幾天前, Dockerfile
工作正常,當我今天再次嘗試構建它時,它在終端中出現以下錯誤。 我嘗試了多個 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 version 17.03.2-ce, build f5ec1e2
版本是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
如果您的主機是 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
應該有一個有效的 nameserver 值,它將被 docker 容器復制。
看起來您的 RUN 指令中有連接錯誤。
嘗試在 Ubuntu 容器中執行相同的命令。
docker run -it ubuntu bash
然后在容器內執行 RUN 命令。
在我的機器上,您的腳本確實有效。
我剛剛更改了我的 VM 播放器網絡設置。 將Network Connection
從bridged mode to NAT
更改bridged mode to NAT
。 現在它的工作
對我有用的解決方案是
檢查我的主機/etc/resolv.conf
- 尋找名稱服務器 xxxx
將那里的名稱服務器復制到我主機的/etc/docker/daemon.json
sudo su
才能cd /etc/docker
nano daemon.json
{
"dns": ["x.x.x.x", "z.z.z.z", "8.8.8.8"]
}
xxxx 和 zzzz 可能是你的域名服務器 8.8.8.8 是谷歌的,你可以試試。
sudo service docker restart
隨着時間的推移,我的域名服務器(在我家)發生了變化,所以我有一些,或者我必須時不時地添加到這個文件中。 如果您在不同的地方使用互聯網,它也可能會發生變化 - 所以這並不總是最好的解決方案。
概述
你的問題有兩個部分:
1.修復臨時解決消息
2. 修復包管理問題
臨時解決
這個問題很可能是:
1. 由於您的互聯網服務提供商沒有正確地將互聯網命名 (DNS) 轉發到其或外部 DNS 服務器,或
2. 由於您的網絡變化同樣阻止了此命名 - 例如,新路由器/調制解調器,使用新配置重新配置交換機。
讓我們看看可能的 DNS 解析問題。
首先,在您的系統中臨時添加一個已知的 DNS 服務器。
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null
然后運行sudo apt update
。
如果這修復了您的臨時解析消息,那么請等待 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
包管理問題
除了臨時解決問題 - 您還有一些包管理問題需要更正。
打開終端並輸入:-
sudo nano /etc/apt/sources.list
並查看您是否從正確的源包下載。
或者
如果你在代理后面使用 -E.for example:-
sudo -E apt-get update
一個簡單的方法是將nslookup archive.ubuntu.com
IP 寫入/etc/hosts
,然后重新啟動 docker。
當然它需要你的/etc/docker/daemon.json
使用主機的 IP。
在我的情況下,daemon.json 中禁用了橋接網絡。
如下修復后,它起作用了。
root@pc:/etc/docker# cat daemon.json
{
"iptables": true,
"bridge": "docker0"
}
並且不要忘記重新啟動:
sudo service docker restart
我還使用了以下有用的命令來調查這個問題:
# List networks (it should have 3 lines bridge, host, none)
docker network ls
# Check the logs, it will have docker log
journalctl -xe
# This one showed me at the end that bridge was missing iptables config like below
# WARNING: bridge-nf-call-iptables is disabled
# WARNING: bridge-nf-call-ip6tables is disabled
docker info
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.