Cannot install packages inside docker Ubuntu image

前端 未结 6 747
生来不讨喜
生来不讨喜 2020-12-07 06:48

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:

a         


        
相关标签:
6条回答
  • 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
    
    0 讨论(0)
  • 2020-12-07 07:37

    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.

    0 讨论(0)
  • 2020-12-07 07:38

    Add following command in Dockerfile:

    RUN apt-get update
    
    0 讨论(0)
  • 2020-12-07 07:39

    From the docs in May 2017 2018 2019 2020

    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”.

    0 讨论(0)
  • 2020-12-07 07:41

    I found that mounting a local volume over /tmp can cause permission issues when the "apt-get update" runs, which prevents the package cache from being populated. Hopefully, this isn't something most people do, but it's something else to look for if you see this issue.

    0 讨论(0)
  • 2020-12-07 07:42

    You need to update the package list in your Ubuntu:

    $ sudo apt-get update
    $ sudo apt-get install <package_name>
    
    0 讨论(0)
提交回复
热议问题