【问题标题】:`docker build` fails trying to install ubuntu packages`docker build` 尝试安装 ubuntu 包失败
【发布时间】:2018-01-20 21:08:59
【问题描述】:

尝试构建一个简单的 ubuntu apache Web 服务器 docker 映像,当 docker build 命令尝试安装软件包时出现错误。我正在使用 Docker 中的 Ubuntu 基础映像来执行此操作。以下是我的 Dockerfile 中的代码;

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

我的主机操作系统是 Mac OSX El Capitan,构建失败时我得到的错误是;

The command '/bin/sh -c apt-get install apache2' returned a non-zero code: 1

我的 docker build 命令是;

docker build -t="webserver" .

请帮忙。提前致谢。

【问题讨论】:

  • 尝试使用额外的命令行开关-it 运行您的容器,它应该打印标准输出,并希望打印来自apt-get 的错误消息(来自similar thread here
  • @chrki,它还没有进入运行阶段,我还在尝试创建一个图像并且 -i 在docker build 中不可用。
  • 在您提供的错误消息上方应该有一条错误消息。你能把它包括进来吗?

标签: macos ubuntu docker dockerfile docker-build


【解决方案1】:

您应该在构建映像时使用 '-y' apt-get 标志。

apt-get 会询问您是否允许继续安装 apache,并且由于在构建映像时您无法与 apt-get 交互,因此您必须将表示“是”的“-y”标志传递给 apt-得到提示。

尝试将其更改为:

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

甚至:

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

【讨论】:

  • 对我来说它不起作用。它给出了无法找到包 apache2 的错误。我正在使用 ubuntu:latest
猜你喜欢
  • 2019-12-05
  • 2023-01-11
  • 1970-01-01
  • 2014-08-18
  • 2017-02-08
  • 2016-01-26
  • 1970-01-01
  • 1970-01-01
  • 2020-08-07
相关资源
最近更新 更多