Unable to run the command for Docker instance of Jenkins

Hi KK Team,

I can run the docker container for jenkins but while persisting the docker instance of jenkins i could not execute the docker command which is present in tutorial.

Attached the snapshot of the command and please help on the same.

Br
SK

Kindly try again after adding the sudo at the start of the command.

Also kindly note that this image is deprecated. Please read Official Jenkins image to use from Docker Hub

So the right image should be : jenkins/jenkins

Reference :

https://hub.docker.com/r/jenkins/jenkins/

Hi there,

still i am getting the same issue and i cannot able to persist my changes for jenkins.

What i did is i have installed new docker images from jenkins/jenkins and i could run the container first time but the changes saving into jenkins_home giving me copy file reference error.

BR
SK

Here is the output of sudo command and i get the same error after running with sudo privilege.

[root@osboxes /]# mkdir my-jenkins-data
[root@osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jen kins_home jenkins/jenkins:lts
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission deni ed
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permiss ions?
[root@osboxes /]#

Hello, @SunilKirangi
We can see that it’s a permission issue, that means my-jenkins-data directory has not enough permission. In the Jenkins’s dockerfile user is set to “jenkins” and you’re attaching directory of “root” user.
Change permission to 757.

$ chmod +757 my-jenkins-data 

Above is creating confusion so adding complete path.

$ chmod +757 /root/my-jenkins-data

Hi KK team,
I have changed the permission as well and have tried before but still the same issue :frowning_face: The whole day it has killed me and help me to solve this issue.

[root@osboxes /]# chmod +757 my-jenkins-data
[root@osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home -u root jenkins/jenkins:lts
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
[root@osboxes /]# ls -l
total 72
lrwxrwxrwx. 1 root root 7 Feb 11 2019 bin → usr/bin
dr-xr-xr-x. 6 root root 4096 Jan 2 08:55 boot
drwxr-xr-x. 19 root root 3180 Jan 2 08:54 dev
drwxr-xr-x. 150 root root 12288 Jan 2 09:09 etc
drwxr-xr-x. 4 root root 4096 Feb 11 2019 home
lrwxrwxrwx. 1 root root 7 Feb 11 2019 lib → usr/lib
lrwxrwxrwx. 1 root root 9 Feb 11 2019 lib64 → usr/lib64
drwx------. 2 root root 16384 Feb 11 2019 lost+found
drwxr-xr-x. 2 root root 4096 Apr 11 2018 media
drwxr-xr-x. 2 root root 4096 Apr 11 2018 mnt
drwxr-xrwx. 2 osboxes root 4096 Jan 2 10:17 my-jenkins-data
drwxr-xr-x. 3 root root 4096 Feb 11 2019 opt
dr-xr-xr-x. 192 root root 0 Jan 2 08:54 proc
dr-xr-x—. 7 root root 4096 Jan 2 09:26 root
drwxr-xr-x. 47 root root 1440 Jan 2 09:09 run
lrwxrwxrwx. 1 root root 8 Feb 11 2019 sbin → usr/sbin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
dr-xr-xr-x. 13 root root 0 Jan 2 08:54 sys
drwxrwxrwt. 18 root root 4096 Jan 2 10:02 tmp
drwxr-xr-x. 13 root root 4096 Feb 11 2019 usr
drwxr-xr-x. 22 root root 4096 Jan 2 09:57 var
[root@osboxes /]# sudo chmod +757 my-jenkins-data
[root@osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home -u root jenkins/jenkins:lts
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
[root@osboxes /]#

@SunilKirangi
Please check path of the directory. It’s available under the “/root/my-jenkins-data” and your directory is available under the path “/” .

Can you please let me know which directory path should be created and I dont know which path you are referring to.
If needed i can send the folder structure of my VM, that will help to understand this issue.

Just to give more details: as explained in the lecturer i have created the my-jenkins-data folder under root and gave all the permission to it.

[root@osboxes /]# ls -l      --> command executed under the path / instead of /root/ so that means directory available under the / path.
total 72
lrwxrwxrwx. 1 root root 7 Feb 11 2019 bin -> usr/bin
dr-xr-xr-x. 6 root root 4096 Jan 2 08:55 boot
drwxr-xr-x. 19 root root 3180 Jan 2 08:54 dev
drwxr-xr-x. 150 root root 12288 Jan 2 09:09 etc
drwxr-xr-x. 4 root root 4096 Feb 11 2019 home
lrwxrwxrwx. 1 root root 7 Feb 11 2019 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Feb 11 2019 lib64 -> usr/lib64
drwx------. 2 root root 16384 Feb 11 2019 lost+found
drwxr-xr-x. 2 root root 4096 Apr 11 2018 media
drwxr-xr-x. 2 root root 4096 Apr 11 2018 mnt
drwxr-xrwx. 2 osboxes root 4096 Jan 2 10:17 my-jenkins-data   --> This one
drwxr-xr-x. 3 root root 4096 Feb 11 2019 opt
dr-xr-xr-x. 192 root root 0 Jan 2 08:54 proc
dr-xr-x—. 7 root root 4096 Jan 2 09:26 root
drwxr-xr-x. 47 root root 1440 Jan 2 09:09 run
lrwxrwxrwx. 1 root root 8 Feb 11 2019 sbin -> usr/sbin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
dr-xr-xr-x. 13 root root 0 Jan 2 08:54 sys
drwxrwxrwt. 18 root root 4096 Jan 2 10:02 tmp
drwxr-xr-x. 13 root root 4096 Feb 11 2019 usr
drwxr-xr-x. 22 root root 4096 Jan 2 09:57 var
[root@osboxes /]# sudo chmod +757 my-jenkins-data    --> This directory available in the / path
[root@osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home -u root jenkins/jenkins:lts     
In the above command directory available in the /root/my-jenkins-data. 
Can you please do $ ls -l /root/ ? Please check the path of directory which you gave with the docker command. 
```

Hi ,

i have

changed the permission as you mentioned and the root folder has execute permission but still its not able to make the file.

Do i need to give full permission for this directory ? i am afraid and last time i have did it but the there was issues in logging as root user.

Hi Player1,
Any update on the issue and do u know the solution to over this problem
Regards
Sunil Kirangi

@SunilKirangi I had the same problem. The issue is related to how you mounted the jenkins home directory volume. That volume is writen to by the container and any user that is running the container. The simple solution is to make a user with the same UID and GID as the user created for Jenkins container, you can find this in your Dockerfile.

The issue can be described here

The real solution is do not mount the container’s volume. The jenkins container uses a specific user with a specific UID and GID.

If you must have the volume mounted try the following:

  • Create a “jenkins” user and assign it the UID:GID of 1000:1000. Then assign all folders even the mounted volume to that user, then run the container as that user.
  • OR if 1000:1000 is already taken by a user, assign the mounted jenkins_home to that user anyway sudo chown -R 1000:1000 jenkins_home/.
    • As root systemctl restart docker.service
    • Then start the container with sudo priv. If its not working as root, try changing to a user to sudo priv and try.

If all else fails, you would need to start over. IF you can get the container up and running again, take backups and screen shots. Delete the volume, and re-deploy without mounting the volume.

1 Like