不要忘记检查你的 apt-get

不要忘记检查你的 apt-get

我正在尝试创建一个 apache + php docker 容器,但是出现了构建错误。

这是我的dockerfile,

FROM ubuntu:14.04

MAINTAINER Mizanur Rahman 

RUN apt-get update
RUN apt-get -y upgrade

RUN apt-get install -y apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur php5-intl

RUN a2enmod php5
RUN a2enmod rewrite

RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php5/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php5/apache2/php.ini

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

# Copy site into place.
ADD www /var/www/site

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

# By default, simply start apache.
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

这是构建输出,

Sending build context to Docker daemon 44.23 MB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
 ---> fa81ed084842
Step 1 : MAINTAINER Mizanur Rahman <[email protected]>
 ---> Using cache
 ---> 4c5dfddabbc7
Step 2 : RUN apt-get update
 ---> Running in 938037477c9c
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Err http://archive.ubuntu.com trusty Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Ign http://archive.ubuntu.com trusty Release
Ign http://archive.ubuntu.com trusty-updates Release
Ign http://archive.ubuntu.com trusty-security Release
Ign http://archive.ubuntu.com trusty/main amd64 Packages/DiffIndex
Ign http://archive.ubuntu.com trusty/restricted amd64 Packages/DiffIndex
Err http://archive.ubuntu.com trusty/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/source/Sources  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/t

最后,这是错误信息

The command [/bin/sh -c apt-get update] returned a non-zero code: 100

我尝试了几种解决方案来解决这个问题,但都没有用。

例如,

Docker 容器无法解析 Ubuntu 14.04 桌面主机上的 DNS

命令 [/bin/sh -c apt-get update] 返回非零代码:100

有人能帮我吗?提前谢谢。

答案1

我在 Ubuntu 镜像上,在 apt-get update 之前我必须添加到 Docker 文件的内容是:

RUN echo Acquire::http::Proxy \"user:[email protected]:port/\"\; >> /etc/apt/apt.conf.d/proxy.conf

这:https://docs.docker.com/config/daemon/systemd/但这还不足以使 apt-get 工作:

ENV HTTP_PROXY="http://user:[email protected]:port"

答案2

您收到以下错误...

没有与主机名关联的地址

一些邪恶的事情发生了解决

主要原因可能是系统的DNS设置错误。

我们如何解决?

首先检查目录 /etc 中是否有 resolv.conf 文件

(这通常是 resolv.conf 文件的主要安装位置)

您可以使用以下命令检查它是否存在...

ls + wc = para 返回存在 0 或 1

0 表示不存在,1 表示存在。

ls /etc|grep resolv.conf|wc -l

ls = find resolv.conf 未找到将返回

ls:无法访问‘/etc/resolv.conf’:没有此文件或目录。

ls /etc/resolv.conf

如果该文件不可用,则需要配置 DNS 解析器。为此,我们将使用 resolv.conf。

安装 resolv.conf 包

apt-get 安装 resolveconf

systemctl 启用 resolvconf.service

打开/etc/resolv.conf使用任何文本编辑器(如 nano)添加你选择的 DNS 记录,例如谷歌 云Flare 四重9 开放域名服务器Resolv.conf 最多接受 3 个不同的名称服务器。

搜索 mylinux 本地主机

名称服务器 8.8.8.8

名称服务器 8.8.4.4

如果您不想使用编辑器访问 /etc/resolv.conf 文件,那么更通用的方法是通过终端使用 echo 应用命令。

echo“搜索 mylinux 本地主机”> /etc/resolv.conf

echo “名称服务器 8.8.8.8” > /etc/resolv.conf

echo“名称服务器 8.8.4.4”> /etc/resolv.conf

请小心,在回显末尾使用 >> 可能会擦除整个文件,并使您的系统没有本地解析器。

使用 ctrl X + Y 完成保存

如果您的系统没有这些变量,现在让我们创建一个参考主机名。

使用您喜欢的编辑器(如 nano)访问 /etc/hosts 文件并添加值。

127.0.1.1 通常用作机器的 FQDN

127.0.1.1 我的Linux

对于支持 IPv4 的主机,以下几行是理想的

127.0.0.1 本地主机

对于支持 IPv6 的主机,以下几行是理想的

::1 本地主机 ip6-本地主机 ip6-环回

ff02::1 ip6-所有节点

ff02::2 ip6-所有路由器

使用 ctrl X + Y 完成保存

让我们在 nsswitch.conf 中添加 dns 变量

访问/etc/nsswitch.conf使用你喜欢的编辑器(例如 nano)编辑文件:

网络:文件

现在

网络:文件 DNS

使用 ctrl X + Y 完成保存

现在在 /etc/host.conf 中为您的主机名添加一个额外的内容(阅读 host.conf 手册)

使用您喜欢的编辑器(如 nano)访问 /etc/host.conf 文件:

如果不存在,请添加下面的文本

订购主机,多开

使用 ctrl X + Y 完成保存

现在我们可以激活 resolv.conf 执行

开始

systemctl 启动 resolvconf.service

地位

systemctl status resolvconf.service

让我们去测试一下...

ping 到 8.8.8.8

ping 8.8.8.8

如果一切顺利的话结果将是:

PING 8.8.8.8 ( 8.8.8.8 ) 56(84) 字节数据。来自 8.8.8.8 的 64 字节:icmp_seq=1 ttl=59 时间=12.0 毫秒来自 8.8.8.8 的 64 字节:icmp_seq=2 ttl=59 时间=12.1 毫秒

不要忘记检查你的 apt-get

一个简短的错误修复...

apt-get --fix-broken 升级

apt-get --fix-broken 安装

apt-get 检查

快速清洁……

apt-get 自动删除

自动清理

我们在这里完成了...

如果问题仍然存在,请继续...

分析您的 sources.list,其中列出 Ubuntu 14.04.6 LTS(Trusty Tahr)作为您的操作系统。

在某些情况下,安装期间配置的 sources.list 可能已损坏,导致您无法在系统上使用 apt-get(具体取决于此映像的构建方式)。一个技巧是检查您的 sources.list 并使用 # 注释掉错误的 URL

使用 apt-get 快速访问路径 /etc/apt/sources.list

apt 编辑源

最后,如果问题仍然存在,请尝试格式化您的系统并从头开始重新安装您的docker。

答案3

您的问题与防火墙设置有关。以root用户身份执行:

sudo iptables -L -n -v

列出所有防火墙规则并检查 FORWARD 链策略。必须将其设置为 ACCEPT,Docker DNS 解析才能正常工作。

如果设置为 DROP 或 REJECT,则执行:

sudo ufw disable

如果你没有安装 ufw,则执行:

sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

相关内容