Jenkins incorrectly resolves volume
I have a virtual machine that hosts Oracle Linux where I installed Docker and created containers using a docker build file. I put jenkins volume under the shared folder but when starting docker compose I got the following error for Jenkins:
jenkins | touch: cannot touch '/var/jenkins_home/copy_reference_file.log: permission denied Jenkins | Unable to write to / var / jenkins_home / copy_reference_file.log. Invalid volume permissions? jenkins exited with code 1
Here's the volume declaration
volumes:
- "/media/sf_devops-workspaces/dev-tools/continuous-integration/jenkins:/var/jenkins_home"
source to share
The problem is that your user in the container has a different user id: groupid as the user on the host.
you have two possibilities:
-
You can ensure that the user in the container has the same user id: groupid as the user on the host who has access to the mounted volume. To do this, you need to set up a user in your Dockerfile. Create a user in dockerfile with the same user id: groupid and then switch to that user https://docs.docker.com/engine/reference/builder/#user
-
You can make sure that the user on the host has the same user id: groupid as the user in the container. To do this, enter a container with
docker exec -it <container-name> bash
and show the user idid -u <username>
id idid -G <username>
. Change the permissions of the mounted volume to this user id: groupid.
source to share
As haschibaschi said, your user in the container has a different user id: groupid than the user on the host.
To work around this, start the container without the (problematic) volume mapping, then start bash on the container:
docker run -p 8080:8080 -p 50000:50000 -it jenkins bin/bash
Once inside the container shell run the id command and you will get results like:
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
Exit the container, navigate to the folder you are trying to display and run:
chown -R 1000:1000 .
Now that the appropriate permissions are compatible, you will need to run the original docker command with the volumes mapped.
source to share