首页 > 解决方案 > 获取失败:在 ubuntu 上安装 apache Web 服务器时出错

问题描述

我正在尝试构建一个 docker 映像。从 Dockerfile 运行 apache Web 服务器的安装命令时,弹出错误。

在此处输入图像描述

注意:我已经在实际文件中添加了 -y 和 apache2-utils 之间的空格。

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/t/tzdata/tzdata_2021a-0ubuntu0.20.04_all.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-bin_2.4.41-4ubuntu3.4_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-data_2.4.41-4ubuntu3.4_all.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.41-4ubuntu3.4_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2_2.4.41-4ubuntu3.4_amd64.deb  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20210119~20.04.1_all.deb  404  Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get install -y apache2' returned a non-zero code: 100

我尝试运行更新命令并再次构建 Dockerfile,但错误仍然存​​在。

标签: dockerapacheubuntu

解决方案


我刚刚使用 Dockerfile 运行了您的示例

FROM ubuntu
MAINTAINER "me"
RUN apt-get update
RUN apt-get install -y apache2
RUN apt-get install -y apache2-utils
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

然后运行docker build .

我没有察觉到您遇到的网络问题,但安装变成了交互式:

Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

  1. Africa      4. Australia  7. Atlantic  10. Pacific  13. Etc
  2. America     5. Arctic     8. Europe    11. SystemV
  3. Antarctica  6. Asia       9. Indian    12. US
Geographic area:

所以你可能想要

  • 重新运行您的代码
  • 确保 apt-get 不会进行交互

最后一点:apt-get clean根本不会使您的图像变小。每个都RUN添加了一个文件系统层,这意味着您将添加一个层来告诉它隐藏文件。为防止这种情况,请将您的调用链接到apt-get一行RUN,如下所示:

RUN apt-get update && apt-get install -y apache2 && apt-get install -y apache2-utils && apt-get clean

推荐阅读