jenkins容器启动时报错权限不足:Can not write to /var/jenkins_home/copy_reference_file.log.

运行jenkins的docker容器提示权限不足
root@debian:~# docker run --name jenkins_zwl -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home jenkins:2.60.3-alpine -u 0 jenkins
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
查看jenkins容器中相应的/var/jenkins_home目录的权限如下(drwxr-xr-x 14 jenkins root 4096 Dec 20 12:58 jenkins_home)
查看命令为:
root@debian:/home# docker run --rm --name jenkins_zwl -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home --entrypoint="/bin/bash" jenkins:2.60.3-alpine -c “ls -al /var”
total 56
drwxr-xr-x 1 root root 4096 Nov 4 2017 .
drwxr-xr-x 1 root root 4096 Dec 20 13:03 …
drwxr-xr-x 1 root root 4096 Nov 4 2017 cache
dr-xr-xr-x 2 root root 4096 May 9 2017 empty
drwxr-xr-x 2 root root 4096 Nov 4 2017 git
drwxr-xr-x 14 jenkins root 4096 Dec 20 12:58 jenkins_home
drwxr-xr-x 5 root root 4096 May 9 2017 lib
drwxr-xr-x 2 root root 4096 May 9 2017 local
drwxr-xr-x 3 root root 4096 May 9 2017 lock
drwxr-xr-x 2 root root 4096 May 9 2017 log
drwxr-xr-x 2 root root 4096 May 9 2017 opt
drwxr-xr-x 2 root root 4096 May 9 2017 run
drwxr-xr-x 3 root root 4096 May 9 2017 spool
drwxrwxrwt 2 root root 4096 May 9 2017 tmp

root@debian:/home# docker run --rm --name jenkins_zwl -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home --entrypoint="/bin/bash" jenkins:2.60.3-alpine -c “ls -al /var/jenkins_home”
total 92
drwxr-xr-x 14 jenkins root 4096 Dec 20 12:58 .
drwxr-xr-x 1 root root 4096 Nov 4 2017 …
drwxr-xr-x 3 jenkins jenkins 4096 Dec 20 12:57 .cache
drwxr-xr-x 3 jenkins jenkins 4096 Dec 20 12:57 .java
-rw-r–r-- 1 jenkins jenkins 1592 Dec 20 12:57 config.xml
-rw-r–r-- 1 jenkins jenkins 302 Dec 20 13:02 copy_reference_file.log
-rw-r–r-- 1 jenkins jenkins 159 Dec 20 12:57 hudson.model.UpdateCenter.xml
-rw------- 1 jenkins jenkins 1712 Dec 20 12:57 identity.key.enc
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:57 init.groovy.d
-rw-r–r-- 1 jenkins jenkins 94 Dec 20 12:57 jenkins.CLI.xml
-rw-r–r-- 1 jenkins jenkins 6 Dec 20 12:57 jenkins.install.UpgradeWizard.state
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:57 jobs
drwxr-xr-x 3 jenkins jenkins 4096 Dec 20 12:57 logs
-rw-r–r-- 1 jenkins jenkins 907 Dec 20 12:57 nodeMonitors.xml
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:57 nodes
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:57 plugins
-rw-r–r-- 1 jenkins jenkins 129 Dec 20 12:58 queue.xml
-rw-r–r-- 1 jenkins jenkins 64 Dec 20 12:57 secret.key
-rw-r–r-- 1 jenkins jenkins 0 Dec 20 12:57 secret.key.not-so-secret
drwxr-xr-x 4 jenkins jenkins 4096 Dec 20 12:57 secrets
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:58 updates
drwxr-xr-x 2 jenkins jenkins 4096 Dec 20 12:57 userContent
drwxr-xr-x 3 jenkins jenkins 4096 Dec 20 12:57 users
drwxr-xr-x 10 jenkins jenkins 4096 Dec 20 12:57 war
查看jenkins容器中jenkins用户id为1000
root@debian:/home# docker run --rm --name jenkins_zwl -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home --entrypoint="/bin/bash" jenkins:2.60.3-alpine -c “cat /etc/passwd | grep jenkins”
jenkins❌1000:1000:Linux User,:/var/jenkins_home:/bin/bash
而本地/var/jenkins用户为权限为root:root,因为该目录为docker进程运行时缺省出来的,因此就比较明了了,把当前目录的拥有者赋值给uid 1000,再启动"jenkins"容器就一切正常了
sudo chown -R 1000 /var/jenkins

root@debian:/home# docker run --name jenkins_zwl -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home jenkins:2.60.3-alpine

猜你喜欢

转载自blog.csdn.net/qq_25650463/article/details/111462749