无法在 docker Ubuntu 映像中安装软件包

新手上路,请多包涵

我在 docker 上安装了 Ubuntu 14.04 映像。之后,当我尝试在 ubuntu 映像中安装包时,我无法找到包错误:

 apt-get install curl

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package curl

如何修复此错误?

原文由 Developer 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 567
2 个回答

是因为镜像中没有包缓存,需要运行:

 apt-get update

在安装软件包之前,如果您的命令在 Dockerfile 中,那么您将需要:

 apt-get -y install curl

要抑制命令的标准输出,请使用 -qq 。例如

apt-get -qq -y install curl

原文由 ISanych 发布,翻译遵循 CC BY-SA 4.0 许可协议

来自 5 月文档20172018201920202021 2022

始终将 RUN apt-get updateapt-get install 组合在同一个 RUN 语句中,例如

RUN apt-get update && apt-get install -y package-bar

(…)

RUN 语句中单独使用 apt-get update --- 会导致缓存问题,随后的 apt-get install 指令会失败。

(…)

使用 RUN apt-get update && apt-get install -y 可确保您的 Dockerfile 安装最新的软件包版本,无需进一步编码或手动干预。这种技术被称为“缓存清除”。

原文由 creimers 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题