How to install packages inside a docker Ubuntu image

+4 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,700 points
47,010 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
• 10,620 points
+1 vote

You could try something like this:

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

Try this:

RUN apt-get update

And then install the package

answered Apr 24, 2019 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, 2019 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

+1 vote
1 answer

How to install packages in a Docker container?

Hi@akhtar, To install packages in a docker container, ...READ MORE

answered Apr 15, 2020 in Docker by MD
• 95,460 points
146,663 views
0 votes
1 answer
0 votes
0 answers

How to install PHP composer inside a docker container

I'm trying to figure out how to ...READ MORE

Apr 12, 2022 in Docker by Abhijeet
• 180 points
6,700 views
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, 2019 in Docker by Sirajul
• 59,230 points
3,751 views
+2 votes
1 answer
+2 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
• 58,100 points
2,687 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
• 10,620 points
3,485 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP