2014-12-03 226 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.