Cannot install packages inside docker Ubuntu image

岁酱吖の 提交于 2019-11-28 13:16:30

问题


I installed Ubuntu 14.04 image on docker. After that, when I try to install packages inside the ubuntu image, I'm getting unable to locate package error:

apt-get install curl

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

How to fix this error?


回答1:


It is because there is no package cache in the image, you need to run:

apt-get update

before installing packages, and if your command is in a Dockerfile, you'll then need:

apt-get -y install curl

To suppress the standard output from a command use -qq. E.g.

apt-get -qq -y install curl



回答2:


From the docs in May 2017 2018 2019

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.

(...)

Using RUN apt-get update && apt-get install -y ensures your Dockerfile installs the latest package versions with no further coding or manual intervention. This technique is known as “cache busting”.




回答3:


Add following command in Dockerfile:

RUN apt-get update



回答4:


Make sure you don't have any syntax errors in your Dockerfile as this can cause this error as well. A correct example is:

RUN apt-get update \
    && apt-get -y install curl \
    another-package

It was a combination of fixing a syntax error and adding apt-get update that solved the problem for me.




回答5:


The error is coming because you don't have the package or you don't have the repo that contains it.

Simple solution you should do apt-get update and then try.




回答6:


You need to update the package list in your Ubuntu:

$ sudo apt-get update
$ sudo apt-get install <package_name>


来源:https://stackoverflow.com/questions/27273412/cannot-install-packages-inside-docker-ubuntu-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!