2014-12-03 223 views
120

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

apt-get install curl 

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

如何解决此错误?

回答

244

这是因为图像没有包缓存,你需要运行:

apt-get -qq update 

安装软件包前,如果你的命令是在Dockerfile,你这时就需要:

在Dockerfile
apt-get -qq -y install curl 
+1

这个工作对我来说,我应该跑-qq所有时间 – 2014-12-03 14:03:17

+5

-qq抑制你通常Dockerfile不需要输出。另一个不错的技巧 - 告诉debconf它在非交互式环境中工作: echo'debconf debconf/frontend select Noninteractive'| debconf-set-selections – ISanych 2014-12-03 14:11:28

+5

出于某种原因,这对我不起作用,仍然是相同的“E:无法找到包..”消息 – tblancog 2016-08-28 02:48:00

7

添加下面的命令: 运行apt-get更新

40

docs2017年三月

Always combine RUN apt-get update with apt-get install in the same RUN statement, for example

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

(...)

Using apt-get update alone in a RUN statement causes caching issues and subsequent apt-get install instructions fail.