关于docker-compose运行jenkins的问题
version: '3' services: jenkins: container_name: 'jenkins-demo' image: jenkins/jenkins:lts restart: always user: 'jenkins:0' ports: - "10006:8080" - "50001:50000" - "10052:10051" volumes: - /src/dokcer/jenkins_demo:/var/jenkins_home:z - /usr/bin/docker:/usr/bin/docker:z - /var/run/docker.sock:/var/run/docker.sock:z
如果这么设置会提示Permission denied即用户不对
如果改为下面这种
version: '3' services: jenkins: container_name: 'jenkins-demo' image: jenkins/jenkins:lts restart: always user: '0' ports: - "10006:8080" - "50001:50000" - "10052:10051" volumes: - /src/dokcer/jenkins_demo:/var/jenkins_home:z - /usr/bin/docker:/usr/bin/docker:z - /var/run/docker.sock:/var/run/docker.sock:z
能够运行,但是到了后面部署的时候,即在构建时候运行shell脚本
docker build --no-cache -t ${image_name}:${port}
会报,会报没有权限,到底这user怎么设置呢?
正在回答 回答被采纳积分+1
我重新整理一遍如下
1. cat /etc/group | grep docker 结果是 dockerroot:x:991:
2. version: '3' services: jenkins: container_name: 'jenkins-demo' image: jenkins/jenkins:lts restart: always user: jenkins:991 ports: - "10006:8080" - "50001:50000" - "10052:10051" volumes: - /src/dokcer/jenkins_demo:/var/jenkins_home - /usr/bin/docker:/usr/bin/docker - /var/run/docker.sock:/var/run/docker.sock
不能运行
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
3. 删掉volume修改如下 version: '3' services: jenkins: container_name: 'jenkins-demo' image: jenkins/jenkins:lts restart: always user: jenkins:991 ports: - "10006:8080" - "50001:50000" - "10052:10051" volumes: - /usr/bin/docker:/usr/bin/docker - /var/run/docker.sock:/var/run/docker.sock 可以运行。但是我还是希望不要删掉vulume
以下是课程中的docker-compose.yml示例:
可以作为参考:
version: '3'
services:
jenkins:
container_name: 'jenkins'
image: jenkins/jenkins:lts
restart: always
user: jenkins:994
ports:
- "10050:8080"
- "50000:50000"
- "10051:10051"
volumes:
- /home/jenkins/data:/var/jenkins_home
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
- /etc/localtime:/etc/localtime
# 需要设置 echo 'Asia/Shanghai' > /etc/timezone
- /etc/timezone:/etc/timezone
报的是没有操作Docker的权限 ?
确定几点:1. 宿主机的docker的执行文件的位置which docker来查看 2. 当映射成功后,在jenkins的内部, 使用docker exec -it jenkins容器名 /bin/bash,来执行docker --version命令试试看看
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星