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"

      

+6


source to share


5 answers


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 id id -u <username>

    id id id -G <username>

    . Change the permissions of the mounted volume to this user id: groupid.

+5


source


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.

+2


source


This error is solved using the following command.

Go to your jenkins data connection path: / media

Run the following command:

cd /media
sudo chown -R ubuntu:ubuntu sf_devops-workspaces

      

restart jenkins dock container

docker-compose restart jenkins

      

0


source


It is easy to fix this using the -u option. Be aware that this will run as root (uid = 0)

docker run -u 0 -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home jenkins/jenkins:lts

      

0


source


I had the same problem solved after disabling SELINUX. It is not recommended to disable SELINUX, so install your own module and enable it. It works. Only changing permissions will not work on CentOS 7.

0


source







All Articles