Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install new packages into non-root Docker Container?

I'm trying to extend a docker container for SOLR. I just want to install vim into it. But when I run the docker build it complains that I'm not root.

This is the DockerFile that I'm extending: https://github.com/makuk66/docker-solr/blob/master/5.3/Dockerfile

And my build file is this:

FROM makuk66/docker-solr MAINTAINER OCSCommerce Team <[email protected]> RUN apt-get update RUN apt-get --assume-yes install vim COPY home/ocscommerce /etc/solr/home 

Then it outputs this:

192.168.99.100 localhost:solr$ docker build -t ocscommerce/solr . Sending build context to Docker daemon 39.66 MB Step 0 : FROM makuk66/docker-solr  ---> 92be2fe79f15 Step 1 : MAINTAINER OCSCommerce Team <[email protected]>  ---> Using cache  ---> a3ac70e40324 Step 2 : RUN apt-get update  ---> Running in c865716a2694 E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/ E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? 

Is there any way to install a package into this container? Or would I need to copy the original build file from makuk66?

like image 309
Richard G Avatar asked Sep 15 '15 02:09

Richard G


People also ask

Can I install Docker without root privileges?

Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container runtime. Rootless mode does not require root privileges even during the installation of the Docker daemon, as long as the prerequisites are met.

How do you add a package to a container?

To install packages in a docker container, the packages should be defined in the Dockerfile. If you want to install packages in the Container, use the RUN statement followed by exact download command . You can update the Dockerfile with latest list of packages at anytime and build again to create new image out of it.


2 Answers

Switch to the root user, then switch back to the original solr user:

USER root  install/updates  USER solr 
like image 108
user1338771 Avatar answered Oct 08 '22 18:10

user1338771


Similar suggestion to the previous answer https://stackoverflow.com/a/37615312/2200690, open an interactive shell as the root user and then install your packages using apt-get.

docker exec --user="root" -it <container_name> /bin/bash 

install the package

apt-get install package 
like image 45
Suketu Bhuta Avatar answered Oct 08 '22 19:10

Suketu Bhuta