Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

Docker Run Permission Issue while setting up volume

I have created a folder my-jenkins-data and changed the permission to chown -R 1000 /root/my-jenkins-data but I get a "permission denied" error when I try to access the bind-mounted directory from a container.

Here is the quick snippet of the command:

[root@osboxes /]# sudo chown -R 1000 /root/my-jenkins-data
[root@osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home 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?
question from:https://stackoverflow.com/questions/65540880/docker-run-permission-issue-while-setting-up-volume

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Jenkins has non-root user that is jenkins.

Try to run

chown -R 1000:1000 /root/my-jenkins-data

Or you can give all permissions to the folder.

chmod -R 777 /root/my-jenkins-data

Or you can create docker volume and attach to Jenkins.

docker volume create jenkins
docker run -p 8033:8080 -v jenkins:/var/jenkins_home -u root jenkins/jenkins:lts

To list volume folder execute get folder location with docker volume inspect jenkins

$ docker volume inspect jenkins
[
    {
        "CreatedAt": "2021-01-02T22:13:07+03:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/jenkins/_data",
        "Name": "jenkins",
        "Options": {},
        "Scope": "local"
    }
]

$ ls /var/lib/docker/volumes/jenkins/_data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...