How to install packages inside a docker Ubuntu image?

+2 votes

After installing Ubuntu image on docker I tried to run packages inside the image. I get an error message which says “unable to locate package”. For example, when I run the below command, I get the following error:

apt-get install curl
Reading package lists... Done

Building dependency tree       

Reading state information... Done

E: Unable to locate package curl

How do I solve this?

Jul 31, 2018 in Docker by Tyrion anex
• 8,270 points
3,093 views
Do apt-get update before installing the package

4 answers to this question.

+1 vote

This happens when there is no package cache in the image, you need to run the following command before installing packages:

apt-get update

If you’re running in a Dockerfile, then you have to follow the below command:

apt-get -y install curl

Finally, to suppress the std o/p use -qq. Example,

apt-get -qq -y install curl
answered Jul 31, 2018 by Sophie may
• 9,530 points
+1 vote

You could try something like this:

docker run ubuntu bash -c "apt-get -y install curl" 
answered Apr 24 by Bishu
+1 vote

Try this:

RUN apt-get update

And then install the package

answered Apr 24 by Pamela
+1 vote

Execute the update and the install command in the same line. Like this:

RUN apt-get update && apt-get install -y package-bar
answered Apr 24 by Vismaya
This worked for me. But why?

using apt-get update alone in a run statement can cause caching issues and subsequent apt-get update install fails.

Related Questions In Docker

0 votes
2 answers

How to execute docker exec commande inside a docker container ?

You need to get inside the container ...READ MORE

answered Aug 13 in Docker by Sirajul
• 25,420 points
279 views
0 votes
1 answer

How to push a docker image to a private repository

You need to tag your image correctly ...READ MORE

answered Jul 26, 2018 in Docker by Kalgi
• 40,460 points
80 views
0 votes
1 answer

How to push a docker image onto the Azure Container Registry (ACR)?

Before pushing local Docker image to ACR, ...READ MORE

answered Jul 4 in Docker by Sirajul
• 25,420 points
113 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,110 points

edited Oct 16, 2018 by lina 4,272 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,520 points
155 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,530 points
325 views
0 votes
2 answers