10
votes

I want to run Jenkins in a Docker Container on Centos7. I saw the official documentation of Jenkins: First, pull the official jenkins image from Docker repository.

docker pull jenkins

Next, run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkins_home from the container is mapped to jenkins/ directory from the current path on the host. Jenkins 8080 port is also exposed to the host as 49001.

docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins

But when I try to run the docker container I get the following error:

/usr/local/bin/jenkins.sh: line 25: /var/jenkins_home/copy_reference_file.log: Permission denied

Can someone tell me how to fix this problem?

2
It works ok. Do you have a write permission to where the container is being run? - Opal
I think it's an issue with that. I think I have to make sure that the container may write something on my host - user5558501
yes you definitely allow the container to write on the host if you want to make it persistent. - Opal

2 Answers

20
votes

The official Jenkins Docker image documentation says regarding volumes:

docker run -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins

This will store the jenkins data in /your/home on the host. Ensure that /your/home is accessible by the jenkins user in container (jenkins user - uid 1000) or use -u some_other_user parameter with docker run.

This information is also found in the Dockerfile. So all you need to do is to ensure that the directory $PWD/jenkins is own by UID 1000:

mkdir jenkins
chown 1000 jenkins
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins
0
votes

The newest Jenkins documentation says to use Docker 'volumes'. Docker is kinda tricky on this, the difference between the two is a full path name with the -v option for bind mount and just a name for volumes.

docker run -d -p 49001:8080 -v jenkins-data:/var/jenkins_home -t jenkins

This command will create a docker volume named "jenkins-data" and you will no longer see the error.

Link to manage volumes: https://docs.docker.com/storage/volumes/