Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install package in running docker container

i've been using a docker container to build the chromium browser (building for Android on Debian 10). I've already created a Dockerfile that contains most of the packages I need.

Now, after building and running the container, I followed the instructions, which asked me to execute an install script (./build/install-build-deps-android.sh). In this script multiple apt install commands are executed.

My question now is, is there a way to install these packages without rebuilding the container? Downloading and building it took rather long, plus rebuilding a container each time a new package is required seems kind of suboptimal. The error I get when executing the install script is:

./build/install-build-deps-android.sh: line 21: lsb_release: command not found

(I guess there will be multiple missing packages). And using apt will give:

root@677e294147dd:/android-build/chromium/src# apt install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package nginx

(nginx just as an example install).

I'm thankfull for any hints, as I could only find guides that use the Dockerfile to install packages.

like image 469
MajorasKid Avatar asked Jul 22 '20 05:07

MajorasKid


People also ask

Can we install Ubuntu on docker?

Overview. It is now possible to run Docker containers on Windows 10 and Windows Server, leveraging Ubuntu as a hosting base. Imagine running your own Linux applications on Windows, using a Linux distribution you are comfortable with: Ubuntu!


2 Answers

You can use docker commit:

  1. Start your container sudo docker run IMAGE_NAME
  2. Access your container using bash: sudo docker exec -it CONTAINER_ID bash
  3. Install whatever you need inside the container
  4. Exit container's bash
  5. Commit your changes: sudo docker commit CONTAINER_ID NEW_IMAGE_NAME

If you run now docker images, you will see NEW_IMAGE_NAME listed under your local images.

Next time, when starting the docker container, use the new docker image you just created:
sudo docker run **NEW_IMAGE_NAME** - this one will include your additional installations.

Answer based on the following tutorial: How to commit changes to docker image

like image 157
Arye Avatar answered Oct 17 '22 04:10

Arye


Thanks for @adnanmuttaleb and @David Maze (unfortunately, they only replied, so I cannot accept their answers).

What I did was to edit the Dockerfile for any later updates (which already happened), and use the exec command to install the needed dependencies from outside the container. Also remember to

apt update

otherwise you cannot find anything...

like image 4
MajorasKid Avatar answered Oct 17 '22 06:10

MajorasKid