Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Building a docker container on top of another image… "permission denied"?

I am trying to build an extension of an existing image with FROM and then apt install additional packages on top and do own customizations. I get permission denied and "are you root" messages. Specifically, this is the image I want to extend:

My Dockerfile:

FROM makarius/isabelle:latest
SHELL ["/bin/bash", "-c"]


# Add dependencies
RUN apt-get update && \
    apt-get install --yes build-essential && \
    apt-get install --yes openjdk-8-jdk && \
    apt-get install --yes xterm && \
    apt-get install --yes iputils-ping && \
    apt-get install --yes vim && \
    apt-get install --yes net-tools && \
    apt-get -y install xauth && \
    apt-get clean   

# user
RUN useradd -m foo && (echo foo:foo | chpasswd)
USER foo

# Setup FOO repository
WORKDIR /home/foo

# ... some commands

ENTRYPOINT ["/bin/bash"]

Building it it seems I can’t get the ability to install anything. There is no sudo in the image.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

root@ub18:/home/x/foo/bar# sudo docker build -t i8:01 -f Dockerfile .
Sending build context to Docker daemon  408.7MB
Step 1/9 : FROM makarius/isabelle:latest
 ---> da948b0dd494
Step 2/9 : SHELL ["/bin/bash", "-c"]
 ---> Using cache
 ---> 64f897ae98ea
Step 3/9 : RUN apt-get update &&    apt-get install --yes build-essential &&    apt-get install --yes openjdk-8-jdk &&  apt-get install --yes xterm &&  apt-get install --yes iputils-ping &&   apt-get install --yes vim &&    apt-get install --yes net-tools &&  apt-get -y install xauth &&     apt-get clean
 ---> Running in 9ec12ecb98e8
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
The command '/bin/bash -c apt-get update &&     apt-get install --yes build-essential &&    apt-get install --yes openjdk-8-jdk &&  apt-get install --yes xterm &&  apt-get install --yes iputils-ping &&   apt-get install --yes vim &&    apt-get install --yes net-tools &&  apt-get -y install xauth &&     apt-get clean' returned a non-zero code: 100

I expect to be able to build the extended image from the existing one, with two users defined and all packages installed. I can get by with a single user as well if have to.

>Solution :

The parent image markarius/isabelle switched user to isabelle, you gotta switch it back to root to run apt-get with additional line USER root before that line in your docker file. There’s no need to use sudo in docker images since by default you already have root access.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading