I am trying to build the OpenJ9 VM and install OpenJDK. Due to some constraints, I must use an older version of OpenJ9, so I am following the instructions given over here. I had installed Docker Desktop on my system from it’s binary a while back and have been using it without any issues.
While following the instructions, I am able to set up my build environment. Once I run the container using the command:
docker run -v <host_directory>:/src -it openj9
A docker container starts running with the prompt:
jenkins@5512b38e49f5:/$
Following the instructions, I tried to clone the OpenJDK extensions inside the container using:
jenkins@5512b38e49f5:/$ git clone https://github.com/ibmruntimes/openj9-openjdk-jdk8.git
fatal: could not create work tree dir 'openj9-openjdk-jdk8': Permission denied
I tried to run the docker container with root permissions:
sudo docker run -v <host_directory>:/src -it openj9
However, to this, I get an error:
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
I noticed that all of my docker commands run successfully without sudo
but they all give the above error when I try to run them with sudo
For example:
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
But running with root:
sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
I thought that running the docker container with elevated privilege would give me the required permissions I am not able to run Docker with sudo
, which is a surprising problem in itself!
I tried to see if the directory which I am cloning into has the required permissions and it seems like I do:
jenkins@976a091d5163:/$ cd src/
jenkins@976a091d5163:/src$ ls -al
total 8
drwxrwxr-x 2 root root 4096 Apr 10 18:30 .
drwxr-xr-x 1 root root 4096 Apr 11 07:55 ..
I am using Linux Mint 21.3 virginia based on Ubuntu 22.04 and Docker Desktop Current version: 4.27.1 (136059).
2
Answers
You can either clone the repositories on the host and use
-v
; or clone within the container in which case-v
is not necessary.Running the container with the flag
-u root
should help.You can see that the permissions of the dir
/src
isIs read and execute for everyone and write is only for user and group,
Since you are not logged in as root as you can see from your prompt:
jenkins@976a091d5163:/src$
You can’t write to this dir.
Running with sudo will not change the user of the container it will run
docker
command it self as sudo look like you need to give the root user on your PC permissions to docker, but it’s not related to the clone issue.