[英]Starting Jenkins in Docker Container
I want to run Jenkins in a Docker Container on Centos7. 我想在Centos7上的Docker容器中运行Jenkins。 I saw the official documentation of Jenkins: First, pull the official jenkins image from Docker repository.
我看到了Jenkins的官方文档:首先,从Docker存储库中提取官方jenkins图像。
docker pull jenkins
Next, run a container using this image and map data directory from the container to the host; 接下来,使用此映像运行容器并将数据目录从容器映射到主机; eg in the example below /var/jenkins_home from the container is mapped to jenkins/ directory from the current path on the host.
例如,在下面的示例中,来自容器的/ var / jenkins_home从主机上的当前路径映射到jenkins /目录。 Jenkins 8080 port is also exposed to the host as 49001.
Jenkins 8080端口也作为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: 但是当我尝试运行docker容器时,我收到以下错误:
/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? 有人能告诉我如何解决这个问题吗?
The official Jenkins Docker image documentation says regarding volumes: 关于卷的官方Jenkins Docker图像文档说:
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.
这会将jenkins数据存储在主机上的/ your / home中。 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.
确保容器中的jenkins用户可以访问/ your / home(jenkins user-uid 1000),或者使用-u some_other_user参数和docker run。
This information is also found in the Dockerfile . 此信息也可在Dockerfile中找到。 So all you need to do is to ensure that the directory
$PWD/jenkins
is own by UID 1000
: 所以你需要做的就是确保UID
1000
拥有目录$PWD/jenkins
:
mkdir jenkins
chown 1000 jenkins
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins
The newest Jenkins documentation says to use Docker 'volumes'. 最新的Jenkins文档称使用Docker'卷'。 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在这方面有点棘手,两者之间的区别是一个完整的路径名,带有-v选项,用于bind mount,只是一个卷的名称。
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. 此命令将创建名为“jenkins-data”的docker卷,您将不再看到错误。
Link to manage volumes: https://docs.docker.com/storage/volumes/ 管理卷的链接: https : //docs.docker.com/storage/volumes/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.