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

Richard G picture Richard G · Sep 15, 2015 · Viewed 44.5k times · Source

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?

Answer

user1338771 picture user1338771 · Jun 3, 2016

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

USER root

install/updates

USER solr