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,280 points
1,356 views
Do apt-get update before installing the package

4 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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,050 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
1 answer

How to execute docker exec commande inside a docker container ?

If your containers are running on the ...READ MORE

answered Jul 19, 2018 in Docker by Kalgi
• 2,620 points
131 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
• 35,720 points
44 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,100 points

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

How to store data in external drive with Docker Postgres:9.3 image?

Apparently, the problem would be in your ...READ MORE

answered Jul 12, 2018 in Docker by Kalgi
• 2,620 points
42 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,100 points
56 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,050 points
209 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.